Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7900941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:05:32+00:00 2026-06-03T09:05:32+00:00

I have this C file ( sample.c ): #include <stdio.h> #define M 42 #define

  • 0

I have this C file (sample.c):

#include <stdio.h>

#define M 42
#define ADD(x) (M + x)

int main ()
{
  printf("%d\n", M);
  printf("%d\n", ADD(2));
  return 0;
}

which I compile with:

gcc -O0 -Wall -g3 sample.c -o sample

Then debug with

gdb ./sample

Output:

GNU gdb (Gentoo 7.3.1 p2) 7.3.1
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /tmp/sample...done.

(gdb) macro list

(gdb) macro expand ADD(2)
expands to: ADD(2)

(gdb) print M
No symbol "M" in current context.

(gdb) q

This used to work. I need this to work, because I am using libraries which #define names for hardware peripherals and memory addresses.

This seems to be in direct contradiction of the behavior that is shown on the Sourceware GDB site).

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:05:33+00:00Added an answer on June 3, 2026 at 9:05 am

    It looks like the macros need to be "brought in scope" one way or another. If you follow exactly the examples in the page you link to, they work as advertised (at least they do for me).

    Example (t.c is your source file):

    $ gcc -O0 -g3 t.c
    
    $ gdb ./a.out
    
    GNU gdb (Gentoo 7.3.1 p2) 7.3.1
    ...
    Reading symbols from .../a.out...done.
    (gdb) info macro ADD
    The symbol `ADD' has no definition as a C/C++ preprocessor macro
    at <user-defined>:-1
                 // Macros not loaded yet
    (gdb) list main
    
    1    #include <stdio.h>
    2    #define M 42
    3    #define ADD(x) (M + x)
    4    int main ()
    5    {
    6      printf("%d\n", M);
    7      printf("%d\n", ADD(2));
    8      return 0;
    9    }
    
    (gdb) info macro ADD
    
    Defined at /home/foo/tmp/t.c:3
    #define ADD(x) (M + x)
                 // Macros "in scope"/loaded
    
    (gdb) macro expand ADD(42)
    
    expands to: (42 + 42)
    
    (gdb) macro expand M
    
    expands to: 42
    
    (gdb) macro expand ADD(M)
    
    expands to: (42 + 42)
    

    Or:

    $ gdb ./a.out
    
    GNU gdb (Gentoo 7.3.1 p2) 7.3.1
    ...
    Reading symbols from .../a.out...done.
    
    (gdb) macro expand ADD(1)
    
    expands to: ADD(1)
                 // Macros not available yet
    
    (gdb) break main
    
    Breakpoint 1 at 0x400538: file t.c, line 6.
    
    (gdb) r
    
    Starting program: /home/foo/tmp/a.out
    Breakpoint 1, main () at t.c:6
    6      printf("%d\n", M);
    
    (gdb) macro expand ADD(1)
    
    expands to: (42 + 1)
                 // Macros loaded
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following program: #include <stdio.h> int main() { printf(This is a
Here is my program: #include <stdio.h> int main(int argc, char **argv) { printf(hello world\n);
I have a sample c file called itoa.cpp as below: #include <stdio.h> #include <stdlib.h>
I have a simple example: #include <stdio.h> #include <errno.h> int main() { int result
I have these (sample) lines in a HTML-file: test.ABC.test test.ABCD.test test.ABCE.test And this Ant
I have this file file.txt which I want to split into many smaller ones.
I have this file structure: folderIWantStuffIn/ - old_stuff Now I want to add some
I have this file which I need to read the first bytes to check
I have this simple XML file : <?xml version=1.0 encoding=utf-8 ?> <Artists> <artist artistId=1>
I have this simple code in my user_controller.rb file #listing all users def index

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.