gdb重置工程根目录
来源:互联网 发布:清华大学网络学堂登录 编辑:程序博客网 时间:2024/06/11 18:11
info sources
#########################################################################################
之后,即使你的源文件1.cpp 放在 /home/bbb下面也是可以找到的了。因为gdb帮你做了字符串替换。
###############################################
9.5 Specifying Source Directories
Executable programs sometimes do not record the directories of the sourcefiles from which they were compiled, just the names. Even when they do,the directories could be moved between the compilation and your debuggingsession.GDB has a list of directories to search for source files;this is called thesource path. Each time GDB wants a source file,it tries all the directories in the list, in the order they are presentin the list, until it finds a file with the desired name.
For example, suppose an executable references the file/usr/src/foo-1.0/lib/foo.c, and our source path is/mnt/cross. The file is first looked up literally; if thisfails,/mnt/cross/usr/src/foo-1.0/lib/foo.c is tried; if thisfails, /mnt/cross/foo.c is opened; if this fails, an errormessage is printed.GDB does not look up the parts of thesource file name, such as /mnt/cross/src/foo-1.0/lib/foo.c.Likewise, the subdirectories of the source path are not searched: ifthe source path is/mnt/cross, and the binary refers tofoo.c, GDB would not find it under/mnt/cross/usr/src/foo-1.0/lib.
Plain file names, relative file names with leading directories, filenames containing dots, etc. are all treated as described above; forinstance, if the source path is/mnt/cross, and the source fileis recorded as ../lib/foo.c,GDB would first try../lib/foo.c, then /mnt/cross/../lib/foo.c, and afterthat—/mnt/cross/foo.c.
Note that the executable search path is not used to locate thesource files.
Whenever you reset or rearrange the source path, GDB clears outany information it has cached about where source files are found and whereeach line is in the file.
When you start GDB, its source path includes only ‘cdir’and ‘cwd’, in that order.To add other directories, use thedirectory
command.
The search path is used to find both program source files and GDBscript files (read using the ‘-command’ option and ‘source’ command).
In addition to the source path, GDB provides a set of commandsthat manage a list of source path substitution rules. Asubstitutionrule specifies how to rewrite source directories stored in the program’sdebug information in case the sources were moved to a differentdirectory between compilation and debugging. A rule is made oftwo strings, the first specifying what needs to be rewritten inthe path, and the second specifying how it should be rewritten.Inset substitute-path, we name these two parts from andto respectively.GDB does a simple string replacementof from with to at the start of the directory part of thesource file name, and uses that result instead of the original filename to look up the sources.
Using the previous example, suppose the foo-1.0 tree has beenmoved from/usr/src to /mnt/cross, then you can tellGDB to replace/usr/src in all source path names with/mnt/cross. The first lookup will then be/mnt/cross/foo-1.0/lib/foo.c in place of the original locationof/usr/src/foo-1.0/lib/foo.c. To define a source pathsubstitution rule, use theset substitute-path
command(see set substitute-path).
To avoid unexpected substitution results, a rule is applied only if thefrom part of the directory name ends at a directory separator.For instance, a rule substituting/usr/source into/mnt/cross will be applied to /usr/source/foo-1.0 butnot to/usr/sourceware/foo-2.0. And because the substitutionis applied only at the beginning of the directory name, this rule willnot be applied to/root/usr/source/baz.c either.
In many cases, you can achieve the same result using the directory
command. However,set substitute-path
can be more efficient inthe case where the sources are organized in a complex tree with multiplesubdirectories. With thedirectory
command, you need to add eachsubdirectory of your project. If you moved the entire tree whilepreserving its internal organization, thenset substitute-path
allows you to direct the debugger to all the sources with one singlecommand.
set substitute-path
is also more than just a shortcut command.The source path is only used if the file at the original location nolonger exists. On the other hand,set substitute-path
modifiesthe debugger behavior to look at the rewritten location instead. So, iffor any reason a source file that is not relevant to your executable islocated at the original location, a substitution rule is the onlymethod available to point GDB at the new location.
You can configure a default source path substitution rule byconfiguring GDB with the‘--with-relocated-sources=dir’ option. Thedirshould be the name of a directory under GDB’s configuredprefix (set with ‘--prefix’ or ‘--exec-prefix’), anddirectory names in debug information underdir will be adjustedautomatically if the installed GDB is moved to a newlocation. This is useful ifGDB, libraries or executableswith debug information and corresponding source code are being movedtogether.
directory dirname …
dir dirname …
Add directory dirname to the front of the source path. Severaldirectory names may be given to this command, separated by ‘:’(‘;’ on MS-DOS and MS-Windows, where ‘:’ usually appears aspart of absolute file names) orwhitespace. You may specify a directory that is already in the sourcepath; this moves it forward, soGDB searches it sooner.
You can use the string ‘$cdir’ to refer to the compilationdirectory (if one is recorded), and ‘$cwd’ to refer to the currentworking directory. ‘$cwd’ is not the same as ‘.’—the formertracks the current working directory as it changes during your GDBsession, while the latter is immediately expanded to the currentdirectory at the time you add an entry to the source path.
directory
Reset the source path to its default value (‘$cdir:$cwd’ on Unix systems). This requires confirmation.
set directories path-list
Set the source path to path-list.‘$cdir:$cwd’ are added if missing.
show directories
Print the source path: show which directories it contains.
set substitute-path from to
Define a source path substitution rule, and add it at the end of thecurrent list of existing substitution rules. If a rule with the samefrom was already defined, then the old rule is also deleted.
For example, if the file /foo/bar/baz.c was moved to/mnt/cross/baz.c, then the command
(gdb) set substitute-path /foo/bar /mnt/cross
will tell GDB to replace ‘/foo/bar’ with‘/mnt/cross’, which will allowGDB to find the filebaz.c even though it was moved.
In the case when more than one substitution rule have been defined,the rules are evaluated one by one in the order where they have beendefined. The first one matching, if any, is selected to performthe substitution.
For instance, if we had entered the following commands:
(gdb) set substitute-path /usr/src/include /mnt/include(gdb) set substitute-path /usr/src /mnt/src
GDB would then rewrite /usr/src/include/defs.h into/mnt/include/defs.h by using the first rule. However, it woulduse the second rule to rewrite/usr/src/lib/foo.c into/mnt/src/lib/foo.c.
unset substitute-path [path]
If a path is specified, search the current list of substitution rulesfor a rule that would rewrite that path. Delete that rule if found.A warning is emitted by the debugger if no rule could be found.
If no path is specified, then all substitution rules are deleted.
show substitute-path [path]
If a path is specified, then print the source path substitution rulewhich would rewrite that path, if any.
If no path is specified, then print all existing source path substitutionrules.
If your source path is cluttered with directories that are no longer ofinterest,GDB may sometimes cause confusion by finding the wrongversions of source. You can correct the situation as follows:
- Use
directory
with no argument to reset the source path to its default value. - Use
directory
with suitable arguments to reinstall thedirectories you want in the source path. You can add all thedirectories in one command.
- gdb重置工程根目录
- java获取工程根目录路径
- Android源码工程根目录文件
- GDB调试大型工程
- 自己的web工程是根目录
- android读取工程根目录下文件内容
- 工程根目录config.json文件说明[官方]
- 怎么样在svn根目录添加一个工程
- 把web工程发布到tomcat根目录
- android读取工程根目录下文件内容
- java web获取工程根目录地址
- Android读取工程根目录下文件内容
- Java获取当前工程的根目录
- 根目录
- java 工程获取路径 web根目录。 项目classpath根目录 各种实用方法 摘抄收藏
- java 工程获取路径 web根目录。 项目classpath根目录 各种实用方法
- java 工程获取路径 web根目录。 项目classpath根目录 各种实用方法 摘抄收藏
- java 工程获取路径 web根目录。项目classpath根目录 各种实用方法
- session(会话)对象
- 使用字节流,字符流FileWriter和BufferedWriter通过复制同一文件,比较它们用时的多少
- 决策树
- 欢迎使用CSDN-markdown编辑器
- 知识点
- gdb重置工程根目录
- Android写入文件到sdcard中
- 学习杂记(三)c语言
- Java——对象初始化顺序
- MTK QT Linux flashtool试用总结
- 机器学习之感知机学习笔记第一篇:求输入空间R中任意一点X0到超平面S的距离
- struts2框架校验文件配置提示The content of element type "validators" must match "(validator)+".
- DDS-正弦-Modelsim和MATLAB
- MTK6577+Android之Camera驱动) ~% d