LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-14-2010, 04:38 AM   #1
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Rep: Reputation: 15
Post how to debug macros under gdb


Hello All,

It seems GDB can not expand or show the macro expansion or its definition under the GDB debug to while debugging the program.

Does anyone has any information on how to debug macros under GDB? Please let me know.


Sample Code:

#include <stdio.h>
#include "sample.h"
#define M 42
#define ADD(x) (M + x)

main ()
{
#define N 28
printf ("Hello, world!\n");
#undef N
printf ("We're so creative.\n");
#define N 1729
printf ("Goodbye, world!\n");
}
Compilation:
gcc -gdwarf-2 -g3 sample.c -o sample
GDB message for the command: " info macro ADD "

The symbol `ADD' has no definition as a C/C++ preprocessor macro
at sample.c:5
included at /usr/include/stdio.h:749
 
Old 06-14-2010, 08:05 AM   #2
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 932Reputation: 932Reputation: 932Reputation: 932Reputation: 932Reputation: 932Reputation: 932Reputation: 932
Have a look here: http://www.delorie.com/gnu/docs/gdb/gdb_70.html
 
Old 06-14-2010, 11:39 AM   #3
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by anishakaul View Post
Hi Anishakaul,

Thank you for your information.

I tried the below:

gdb> info macro ADD

The symbol `ADD' has no definition as a C/C++ preprocessor macro
at sample.c:5
included at /usr/include/stdio.h:749

I could not "display" or "expand" the macro definition under GDB.
 
Old 06-14-2010, 12:32 PM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by dayalan_cse View Post
Thank you for your information.
...
I could not "display" or "expand" the macro definition under GDB.
Did you follow from that link to the page it links which tells you the required change to your compile command needed to make any of that work?

http://www.delorie.com/gnu/docs/gdb/gdb_17.html

Especially the phrase there:
Quote:
Version 3.1 of GCC, the GNU C compiler, provides macro information if you specify the options `-gdwarf-2' and `-g3'
I haven't tried any of that myself, so I would guess from that documentation that GCC versions earlier than 3.1 lack the feature and GCC versions later than 3.1 probably still support that feature.

Assuming you compiled without those extra switches, GDB obviously can't use information that GCC didn't make available to it.

Last edited by johnsfine; 06-14-2010 at 12:35 PM.
 
1 members found this post helpful.
Old 06-14-2010, 10:36 PM   #5
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
how to debug macros under gdb

Quote:
Originally Posted by johnsfine View Post
Did you follow from that link to the page it links which tells you the required change to your compile command needed to make any of that work?

http://www.delorie.com/gnu/docs/gdb/gdb_17.html

Especially the phrase there:


I haven't tried any of that myself, so I would guess from that documentation that GCC versions earlier than 3.1 lack the feature and GCC versions later than 3.1 probably still support that feature.

Assuming you compiled without those extra switches, GDB obviously can't use information that GCC didn't make available to it.
Hi Johnsfine,

Thanks for the information.

My compilation switches:

gcc -gdwarf-2 -g3 sample.c -o sample

My gcc compiler version: 3.4.6

GDB still does not show the information about the macro while i was debugging.
 
Old 06-17-2010, 02:06 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,727

Rep: Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043
Did you call the list command first? The page says
Quote:
GDB uses the current listing position to decide which macro definitions are in scope:
I missed that the first time I skimmed through, it seems like surprising behaviour.
Code:
~/tmp/macro$ gdb -q sample
Reading symbols from /home/npostavs/tmp/macro/sample...done.
(gdb) info macro ADD
The symbol `ADD' has no definition as a C/C++ preprocessor macro
at <user-defined>:-1
(gdb) list main
3	
4	#define M 42
5	#define ADD(x) (M + x)
6	
7	main ()
8	{
9	#define N 28
10	  printf ("Hello, world!\n");
11	#undef N
12	  printf ("We're so creative.\n");
(gdb) info macro ADD
Defined at /home/npostavs/tmp/macro/sample.c:5
#define ADD(x) (M + x)
(gdb)
 
Old 06-29-2010, 06:24 AM   #7
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
how to debug macros under gdb

Quote:
Originally Posted by ntubski View Post
Did you call the list command first? The page says

I missed that the first time I skimmed through, it seems like surprising behaviour.
Code:
~/tmp/macro$ gdb -q sample
Reading symbols from /home/npostavs/tmp/macro/sample...done.
(gdb) info macro ADD
The symbol `ADD' has no definition as a C/C++ preprocessor macro
at <user-defined>:-1
(gdb) list main
3	
4	#define M 42
5	#define ADD(x) (M + x)
6	
7	main ()
8	{
9	#define N 28
10	  printf ("Hello, world!\n");
11	#undef N
12	  printf ("We're so creative.\n");
(gdb) info macro ADD
Defined at /home/npostavs/tmp/macro/sample.c:5
#define ADD(x) (M + x)
(gdb)

Hi,

Thanks for the information.

I still dont see macro definition under GDB after listing main.

GDB version used: 6.3.0.0-1.153

What command line options you have used to build your sample.c?
What GDB version you are using?

Thanks,
Deenadayalan
 
Old 06-29-2010, 09:24 AM   #8
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,727

Rep: Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043Reputation: 2043
GNU gdb (GDB) 7.0.1-debian
gcc (Debian 4.4.4-5) 4.4.4

Code:
gcc -g3 -o sample sample.c
also works with
gcc -gdwarf-2 -g3 -o sample sample.c
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debug using gdb and gdbserver Hachaso Programming 0 06-05-2009 03:56 PM
cannot debug with gdb ufmale Programming 9 04-27-2009 05:21 PM
how can I debug the interactinve program with GDB bigapple Programming 1 08-03-2005 09:55 PM
Using gdb to debug different arhitectures george_mercury Linux - Software 1 01-07-2005 06:19 PM
how to debug multithread using GDB? ryanux Programming 1 05-11-2004 12:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration