using GNU debugger on g95 executable

178 views
Skip to first unread message

Sourav

unread,
Apr 9, 2013, 7:02:56 AM4/9/13
to gg...@googlegroups.com

Group members,

I want to study the call tree of g95 using gdb (GNU debugger). To elaborate with an example, suppose I give the following program to g95 to compile:

! add.f90

program test

implicit none

int a,b,c

a=1

b=2

c=a+b

end program test

I want to trace the C language functions in g95's source code that are called while compiling add.f90. For example, the function ‘match g95_match_assignment(void)’ in match.c is called at lines 5, 6 and 7 in add.f90 (and returns ‘MATCH_YES’). Using gdb, I want to determine, when the compiler reaches line 5 of add.f90, which function(s) called g95_match_assignment and which function(s) were called by g95_match_assignment. I want such a call-trace for every line of add.f90.

I invoke gdb as follows and get the following output:

$ gdb --args /path/to/g95/install/directory/bin/i686-pc-linux-gnu-g95 add.f90

(gdb) info functions g95_match_assignment

All functions matching regular expression "g95_match_assignment":

(gdb) info functions match_assignment

All functions matching regular expression "match_assignment":

(gdb) info functions match

All functions matching regular expression "match":

File /path/to/gcc-4.0.3//gcc/gcc.c:

static unsigned char input_suffix_matches(const char *, const char *);

static void mark_matching_switches(const char *, const char *, int);

static unsigned char switch_matches(const char *, const char *, int);

(gdb) quit

I fail to understand why gdb does not list g95_match_assignment .  I configured g95-0.94 as follows:

./configure --prefix=/path/to/g95/install/directory/ --with-gcc-dir=/home/dell/sourav/compressed/gcc-4.0.3/ CFLAGS=-g --enable-debug

Could you please explain to me why gdb does not list the functions inside parse.c and match.c? Is the debugging info stripped at any stage of make-ing g95?

Thanks in advance,

Sourav






Sourav

unread,
Apr 12, 2013, 3:02:44 PM4/12/13
to gg...@googlegroups.com
HI,

I found the solution to my own problem. I should have given the correct executable to gdb to debug. As written in g95's help (g95 --help), the option -v can be used to "Display the programs invoked by the compiler". One of those programs is

"/path/to/g95/install/directory/bin/../lib/gcc-lib/i686-pc-linux-gnu-g95/4.0.3//f951"

which I presume is the front-end of g95.
Now I can invoke gdb as follows and study the call tree of g95's C source code:

gdb --args /path/to/g95/install/directory/bin/../lib/gcc-lib/i686-pc-linux-gnu-g95/4.0.3//f951 add.f90
(gdb) info functions parse
All functions matching regular expression "parse":

File f95-lang.c:
static void be_parse_file(int);

File module.c:
static atom_type parse_atom(void);
static void parse_integer(int);
static void parse_name(int);
static void parse_string(void);

File parse.c:
void g95_parse_file(void);
static void parse_block_data(void);
static void parse_contained(int);
static void parse_critical_block(void);
static void parse_derived(void);
static void parse_do_block(void);
static void parse_enum(void);
static g95_statement parse_executable(g95_statement);
<<snipped>>

Hooray!


Reply all
Reply to author
Forward
0 new messages