Take the 2-minute tour ×

I have a foo.c source file which has the following function implementation:

#include "header.h"
void PREFIX(function_name)(){

I'll copy this file into two directories (dir1 and dir2). In dir1, I have header.h like this:

#define PREFIX(a) prefix1_ ## a

and in dir2, I have header.h like:

#define PREFIX(a) prefix2_ ## a

Therefore, during the linking process, I'll have two different function names.

My problem comes up when I want to use gdb to debug this function and I need to set a breakpoint in a specific line within this function. If I do:

b foo.c:235

and 235 is a line inside the function implementation, in which function is gdb going to actually set the breakpoint? prefix1_function_name or prefix2_function_name ?

Is there a way to make gdb set the breakpoint on both ?


share|improve this question
In my opinion, you should re-think your approach here. Why do you want two different names for the same function? It seems like a way to make the code unnecessarily confusing and hard to maintain. At any rate, I believe it will be in both but I don't know. It seems that you could test it fairly quickly by setting the breakpoint, calling the function both ways, and using backtrace to verify the call path. –  dbeer Oct 10 '11 at 20:50
add comment

1 Answer

Why not just try it out? When I tried it, it set a break point in both files:

(gdb) break a.c:5
Breakpoint 1 at 0x100000e87: file 3/a.c, line 5.
Breakpoint 2 at 0x100000e75: file 2/a.c, line 5.
warning: Multiple breakpoints were set.
Use the "delete" command to delete unwanted breakpoints.

If you want to break in only a specific file, just use the full path name to that file to disambiguate.

share|improve this answer
add comment

Your Answer


