user2381442
user2381442

Reputation: 33

How to check as to in which file is a variable declared while debugging in gdb?

I am going through code which is spread across multiple files. I have a variable x which i am using in file A.c and its declared in B.h. I am debugging using gdb under emacs. While in file A.c how do i check as to in which file is my variable x declared?

Upvotes: 2

Views: 581

Answers (1)

Kamath
Kamath

Reputation: 4684

Try

info variables <variable name>

Its a regex search, so the resultant list might be long.

UPDATE

Since its a regex search try appensing ^ at start and $ at end to get exact match (there might be some better methods, I am no master at regex).

info variables ^<variable name>

If its too annoying try extending GDB commands to do this.

(gdb)define vardef
(gdb)info variables ^$arg0$
(gdb)end

usage

(gdb) vardef <variable name>

You and add this extension to start up script.

P.S. In all instances of variable name above drop "<>"

Upvotes: 3

Related Questions