Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Debug source lookup question

On Wednesday 19 November 2008 17:52:46 Mikhail Khodjaiants wrote:

Hi Mikhail,

> As far as I remember this functionality was added in attempt to
> "synchronize" the external (CDT) source lookup with GDB. I haven't been
> aware it has such an effect. What's the purpose of this command then?

The answer is somewhat long. Most often, binaries compiled with gcc
and typical build systems have two bits of information for every source

	- the name of the file (without directory)
	- the compilation directory

The GDB search path is a list of directories, and may include special
'$cdir' element. When GDB wants to find the fullname of a file, it
checks for it each directory in the search path. If $cdir is found,
it checks in the compilation directory from the debug info.

The default search path includes $cdir already, so if you don't do
any explicit 'dir' commands only compilation directory and current
directory are searched.

The problem is that paths passed via 'dir' or '-environment-directory'
are added in front of the search path. So, it overrides the compilation
directory. And if you have file name a.c in two different directories,
and you add both those directories via -environment-directory, you're
out of luck. Note that adding $cdir in the front will not work, in 
general, for example if the binary is run on a different system from where 
it was compiled.  I think this is the fundamental limitation of a system
where N source directories are specified and searched in order. The best
approach is
	- Not used 'dir' at all when application is built and debugged
	on the same system
	- Use GDB path substitution mechanisms otherwise, documented at
	This is only available in recent versions of GDB.

I'm also not quite sure how this all meshes with the CDT model. Probably,
search path should not include any directories by default. Then users
would add it if all the standard mechanisms in GDB fail.

> Regarding getSourcePaths: it was added to get the source lookup
> information from GDB and populate the CDT source lookup. But the idea
> has never materialized. I am not aware of any future plans for it.

Should this maybe be dropped from source code? The only possible use case
for this is detecting when user typed 'dir' in GDB console, which does not
seem like a very important use case.


Back to the top