6

I'm trying to debug some additions I made to a fairly large c program using gdb. The program I'm trying to debug makes extensive use of #define statements to set different values that are used throughout the code. I need to be able to see what these values are in order to help my debugging (as they include some very important information.

After some digging around I found that the info macro FOO and macro expand FOO commands should be able to print these values if the -g3 option (also tried the -gdwarf-2 and -ggdb3 flags as well) is passed to the compiler (as discussed here). However, whenever I try using this I get

The symbol `FOO' has no definition as a C/C++ preprocessor macro
at <user-defined>:-1

Now, I'm sure that the macro is defined otherwise the previous line of code would not have been able to run. In addition, I'm certain that I have passed the -g3 flag to the compiler. I have one idea as to where the issue might be and that is the location that the macro is defined at. Currently the macro is defined in a header file that is not in the same directory as the rest of the files (i.e. if the source files are in /foo/bar/blam/.. then the macro is defined in /def/mac/here/. Given this I thought maybe the problem was that gdb didn't know to look in this directory so I tried issuing the directory command in gdb and gave it the path to the directory containing the header file (base on this). This still did not solve the problem.

Does anyone know how I can get the values of these macros? If it is pertinent I'm running gdb version 7.11 and compiling the program using cc and gcc both with Apple LLVM version 7.0.2 (clang-700.1.81). Also, gdb was installed/built using homebrew.

Community
  • 1
  • 1
Andrew
  • 693
  • 6
  • 19
  • 1
    Now you know why people are not all that enamoured of the C preprocessor. It makes this sort of thing hard — for the debugger and the person doing the debugging. – Jonathan Leffler Jul 18 '16 at 20:41
  • @JonathanLeffler I certainly understand. This is actually one of my first forays into c programming so it's even more frustrating – Andrew Jul 18 '16 at 20:42
  • 2
    Welcome to the Deep End. Don't forget to surface to breathe. – Jonathan Leffler Jul 18 '16 at 20:42
  • My understanding is that `clang` doesn't yet emit macro debug info. (Despite the existence of a `gcc` command, if you run it you're actually running `clang`. You can install the original `gcc` with homebrew.) – Mark Plotnick Jul 18 '16 at 22:31
  • @MarkPlotnick I tried switching out and using the `gnu gcc` (version 6.1.0) and still have the same problem. Would I also need to switch to something else for `ranlib` and `ar` or can they stay the same as installed? – Andrew Jul 19 '16 at 13:43
  • I don't know if ranlib or ar need to be the GNU versions. – Mark Plotnick Jul 19 '16 at 13:57

0 Answers0