GDB Manual 15 1

15.1 Commands to specify files 指定文件的命令

You may want to specify executable and core dump file names. The usual way to do this is at start-up time, using the arguments to GDB's start-up commands (see section Getting In and Out of GDB).

你可能想指定可执行文件和 core dump 文件的名称。通常是在启动的时候,传递参数给启动 GDB 的命令(请看段“进入与退出 GDB”)

Occasionally it is necessary to change to a different file during a GDB session. Or you may run GDB and forget to specify a file you want to use. Or you are debugging a remote target via gdbserver (see section file). In these situations the GDB commands to specify new files are useful.

有时候需要在 GDB 的会话过程中改变为一个不同的文件。或者你可能在运行 GDB 後,忘记指定你想要的文件。或者你是在通过 gdbserver 调试一个远程目标(请看段“文件”)。在这些情况下,用于指定新文件的 GDB 命令就变得很有用了。

file filename 

Use filename as the program to be debugged. It is read for its symbols and for the contents of pure memory. It is also the program executed when you use the run command. If you do not specify a directory and the file is not found in the GDB working directory, GDB uses the environment variable PATH as a list of directories to search, just as the shell does when looking for a program to run. You can change the value of this variable, for both GDB and your program, using the path command.

使用 filename 作为要调试的程序。它的符号表被读取,或者是单一的内存的内容。它也是你运行run命令时执行的程序。如果没有指定目录,这一文件也没有在 GDB 的工作目录中找到,GDB 将使用环境变量 PATH 作为要搜索的目录列表,就像 shell 查找要运行的程序一样。你可以改变这一变量的值,用于 GDB 和你的程序,请使用 path 命令。

You can load unlinked object `.o' files into GDB using the file command. You will not be able to "run" an object file, but you can disassemble functions and inspect variables. Also, if the underlying BFD functionality supports it, you could use gdb -write to patch object files using this technique. Note that GDB can neither interpret nor modify relocations in this case, so branches and some initialized variables will appear to go to the wrong place. But this feature is still handy from time to time.

你可以使用 file 命令在 GDB 中载入没有被链接的 ".o" 文件。你将不可能“运行”一个这样的对象文件,但是你可以反汇编函数和观察变量。同时,如果内在的 BFD 功能性地支持它,你可以使用这一技术用 gdb-write 给对象文件打上补丁。注意在这种情况下,GDB 既不能转换,也不能修改重定向表,所以函数分支和一些已初始化的变量看起来是呆在不合适的地方。但是这一特征将始终被保留,以备不时之需。

file 

file with no argument makes GDB discard any information it has on both executable file and the symbol table.

没有参数的 file 使 GDB 丢弃可执行程序和符号表中的任何信息。

exec-file [ filename ] 

Specify that the program to be run (but not the symbol table) is found in filename. GDB searches the environment variable PATH if necessary to locate your program. Omitting filename means to discard information on the executable file.

指定在 filename 中找到的要运行的程序(不是符号表)。GDB 根据需要查找 PATH 变量以定位指定的程序。省略 filename 意味放弃可执行文件的信息。

symbol-file [ filename ] 

Read symbol table information from file filename. PATH is searched when necessary. Use the file command to get both symbol table and program to run from the same file.

从 filename 中读符号表信息。同样地根据需要查找 PATH。使用 file 命令从同一文件得到符号表和要运行的程序。

symbol-file with no argument clears out GDB information on your program's symbol table.

symbol-file 没有参数时,清除 GDB 中的程序的符号表信息。

The symbol-file command causes GDB to forget the contents of some breakpoints and auto-display expressions. This is because they may contain pointers to the internal data recording symbols and data types, which are part of the old symbol table data being discarded inside GDB.

symbol-file 命令让 GDB 忘记一些断点和 auto-display 表达式的内容。这是因为他们可能包含指向内部数据 (记录符号和数据类型) 的指针(旧的被 GDB 放弃的符号表的一部分)。

symbol-file does not repeat if you press RET again after executing it once.

在执行 symbol-file 一次之後,如果按下回车键,它并不会重复执行。

When GDB is configured for a particular environment, it understands debugging information in whatever format is the standard generated for that environment; you may use either a GNU compiler, or other compilers that adhere to the local conventions. Best results are usually obtained from GNU compilers; for example, using gcc you can generate debugging information for optimized code.

当 GDB 为一个特别的环境配置好後,它识别这一环境中产生的标准的不分格式的调试信息;你既可以使用一个 GNU 的编译器,也可以使用遵循本地习惯的编译器。最好的选择通常来自 GNU 的编译器;比如,使用 gcc 可以产生优化的代码的调试信息。

For most kinds of object files, with the exception of old SVR3 systems using COFF, the symbol-file command does not normally read the symbol table in full right away. Instead, it scans the symbol table quickly to find which source files and which symbols are present. The details are read later, one source file at a time, as they are needed.

对大多数对象文件来说,老的SVR3系统使用COFF,symbol-file 命令并不马上读取符号表。而是快速地扫描符号表,找出哪些源文件,还有哪些符号表是存在的。更多的细节信息将在随後读取,一次读一个所需的源文件。

The purpose of this two-stage reading strategy is to make GDB start up faster. For the most part, it is invisible except for occasional pauses while the symbol table details for a particular source file are being read. (The set verbose command can turn these pauses into messages if desired. See section Optional warnings and messages.)

two-stage 的读取策略是让GDB启动更快。在多数情况下,当一个源文件的符号表细节信息被读取的时候,存在一定的暂停。(set verbose 命令可以让这些暂停显示需要的信息,请看段“可选的警告和消息”)

We have not implemented the two-stage strategy for COFF yet. When the symbol table is stored in COFF format, symbol-file reads the symbol table data in full right away. Note that "stabs-in-COFF" still does the two-stage strategy, since the debug info is actually in stabs format.

我们还没有实现针对 COFF 的 two-stage 。当符号表被存储为 COFF 格式时,symbol-file 立刻完全地读取符号表。注意“stabs-in-COFF”仍然做 two-stage 策略,因为调试信息实际上是 stab 格式的。

symbol-file filename [ -readnow ] 
file filename [ -readnow ] 

You can override the GDB two-stage strategy for reading symbol tables by using the `-readnow' option with any of the commands that load symbol table information, if you want to be sure GDB has the entire symbol table available.

如果你想确定 GDB 读取了整个符号表,你可以使用“-readnow”选项调整 GDB 的读取符号表的 two-stage 策略,这一选项在所有的载入符号表的命令中存在。

core-file [filename] 
core 

Specify the whereabouts of a core dump file to be used as the "contents of memory". Traditionally, core files contain only some parts of the address space of the process that generated them; GDB can access the executable file itself for other parts.

指定要用作“内存内容”的 core dump 文件。按照惯例,core 文件只包含部分产生他们的进程的地址空间;GDB 可以访问可执行文件以得到其他的部分。

core-file with no argument specifies that no core file is to be used.

core-file 不带参数表示不使用core文件。

Note that the core file is ignored when your program is actually running under GDB. So, if you have been running your program and you wish to debug a core file instead, you must kill the subprocess in which the program is running. To do this, use the kill command (see section Killing the child process).

注意 core 文件在你的程序运行于 GDB 下时是被忽略的。所以,如果你正在运行一个程序,而想改为调试一个 core 文件,那么你必须杀死程序运行的进程。要做这一事情,使用kill命令(请看段“杀死子进程”)。

add-symbol-file filename address 
add-symbol-file filename address [ -readnow ] 
add-symbol-file filename -ssection address ... 

The add-symbol-file command reads additional symbol table information from the file filename. You would use this command when filename has been dynamically loaded (by some other means) into the program that is running. address should be the memory address at which the file has been loaded; GDB cannot figure this out for itself. You can additionally specify an arbitrary number of `-ssection address' pairs, to give an explicit section name and base address for that section. You can specify any address as an expression.

add-symbol-file 命令从 filename 中读取增加的符号表信息。你将在 filename 被动态载入运行中的程序(通过一些其他的途径)时使用这一命令。address 是文件被载入时的地址;GDB 不能指出这一点。你可以指定任意数量的“-ssection address”对,以给出显式的段名和基地址。你可以把address指定为表达式。

The symbol table of the file filename is added to the symbol table originally read with the symbol-file command. You can use the add-symbol-file command any number of times; the new symbol data thus read keeps adding to the old. To discard all old symbol data instead, use the symbol-file command without any arguments.

filename 的符号表被增加到使用 symbol-file 命令读取的符号表中。你可以任意次地使用 add-symbol-file 命令:新的符号就这样被增加到旧的之上。要丢弃所有旧的符号数据,使用不带参数的 symbol-file 命令。

Although filename is typically a shared library file, an executable file, or some other object file which has been fully relocated for loading into a process, you can also load symbolic information from relocatable `.o' files, as long as:

虽然 filename 通常是一个共享库文件,一个可执行文件,或者其他为了载入进程而完全重分配的对象文件,你也可以从可重定位的“.o”文件中载入符号信息。只要:

• the file's symbolic information refers only to linker symbols defined in that file, not to symbols defined by other object files,

• 文件的符号信息都在这一文件中,而不指向其他的对象文件。

• every section the file's symbolic information refers to has actually been loaded into the inferior, as it appears in the file, and • you can determine the address at which every section was loaded, and provide these to the add-symbol-file command.

• 文件符号信息有关的每个段实际上已被载入 inferior,就像在文件中显示的一样。并且你可以决定每个段载入的地址,提供它们给 add-symbol-file 命令。

Some embedded operating systems, like Sun Chorus and VxWorks, can load relocatable files into an already running program; such systems typically make the requirements above easy to meet. However, it's important to recognize that many native systems use complex link procedures (.linkonce section factoring and C++ constructor table assembly, for example) that make the requirements difficult to meet. In general, one cannot assume that using add-symbol-file to read a relocatable object file's symbolic information will have the same effect as linking the relocatable object file into the program in the normal way.

一些嵌入式系统,比如 Sun Chorus 和 VxWorks ,可以载入可重定位的文件到一个已经运行的系统;这些系统可以让需求很容易地得到满足。然而,要认识到的重要的一点是,许多本地系统使用复杂的链接过程(比如.linkonce段因子和C++构造表的装配),而让需求很难得到满足。通常来说,我们不能假定使用 add-symbol-file 读取一个可重定位的对象文件的符号信息,和链接这一对象文件到程序是一样的效果。

add-symbol-file does not repeat if you press RET after using it.

add-symbol-file 在你使用它後按下回车时,并不重复执行。

add-symbol-file-from-memory address 

Load symbols from the given address in a dynamically loaded object file whose image is mapped directly into the inferior's memory. For example, the Linux kernel maps a syscall DSO into each process's address space; this DSO provides kernel-specific code for some system calls. The argument can be any expression whose evaluation yields the address of the file's shared object file header. For this command to work, you must have used symbol-file or exec-file commands in advance.

从一个给定的 address 中读取符号,它在一个动态载入的对象文件中,它的映像直接映射较低的内存中。比如,linux 内核映射一个系统调用DSO到每个进程的地址空间;这一DSO提供了一些系统调用的核心指定的代码。参数可以是任何表达式,对它的评估倾向于文件的共享对象的文件头的地址。要让这一命令工作,你必须预先使用 symbol-file 或者exec-file 命令。

add-shared-symbol-files library-file 
assf library-file 

The add-shared-symbol-files command can currently be used only in the Cygwin build of GDB on MS-Windows OS, where it is an alias for the dll-symbols command (see section 18.1.5 Features for Debugging MS Windows PE executables). GDB automatically looks for shared libraries, however if GDB does not find yours, you can invoke add-shared-symbol-files. It takes one argument: the shared library's file name. assf is a shorthand alias for add-shared-symbol-files.

add-shared-symbol-files 现在只能用于微软操作系统上的 Cygwin 环境上编译的GDB,在那里它是 dll-symbols 命令的一个变种(请看段“调试微软 PE 格式的程序”)。GDB 自动查找共享库,如果没有找到你的共享库时,你可以调用 add-shared-symbol-files,它使用一个参数:共享库文件的名称。assf 是add-shared-symbol-files 一个简写的别名。

section section addr 

The section command changes the base address of the named section of the exec file to addr. This can be used if the exec file does not contain section addresses, (such as in the a.out format), or when the addresses specified in the file itself are wrong. Each section must be changed separately. The info files command, described below, lists all the sections and their addresses.

section 命令改变命名的可执行文件 section 的基地址为 addr。在可执行文件没有包含段地址时这是有用的(比如a.out的格式),或者当文件中指定的地址是错误的。每个段必须被单独地改变。下面描述的info files命令,列出了所有的段和他们的地址。

info files 
info target 

info files and info target are synonymous; both print the current target (see section Specifying a Debugging Target), including the names of the executable and core dump files currently in use by GDB, and the files from which symbols were loaded. The command help target lists all possible targets rather than current ones.

info files 和 info target 是同义的;都打印当前的目标(请看段“指定一个调试目标”),包含可执行文件的名字和当前 GDB 使用的 core dump 文件,还有载入符号的文件。help target 命令列出所有可能的 target,而不仅是当前的那一个。

maint info sections 

Another command that can give you extra information about program sections is maint info sections. In addition to the section information displayed by info files, this command displays the flags and file offset of each section in the executable and core dump files. In addition, maint info sections provides the following command options (which may be arbitrarily combined):

另一个能给你有关程序段的额外信息的命令是 maint info sections。作为对 info files 显示的信息的增加,这一命令显示标记和在可执行文件及core dump 文件中的每个段的文件偏移。另外,maint info sections 提供下面的命令行选项(可以随意的组合):

ALLOBJ 

Display sections for all loaded object files, including shared libraries.

显示所有载入的对象文件的段,包括共享库。

sections 

Display info only for named sections.

只显示名为sections的段的信息。

section-flags 

Display info only for sections for which section-flags are true.

只显示 section-flags 设为 true 的段。


The section flags that GDB currently knows about are:

GDB 当前支持的段标记有:

ALLOC 

Section will have space allocated in the process when loaded. Set for all sections except those containing debug information.

在载入时,段将有空间分配在进程中。除了包含调试信息的段外,都将被设置。

LOAD 

Section will be loaded from the file into the child process memory. Set for pre-initialized code and data, clear for .bss sections.

段从文件中载入,进入子进程的内存。在预初始化的代码和数据中设置,在 .bss 段中清除。

RELOC 

Section needs to be relocated before loading.

段需要在载入前被重定位

READONLY 

Section cannot be modified by the child process.

段不能被子进程修改。

CODE 

Section contains executable code only.

段只包含可执行代码。

DATA 

Section contains data only (no executable code).

段只包含数据(没有可执行代码)。

ROM 

Section will reside in ROM.

段将保持在 ROM 中。

CONSTRUCTOR 

Section contains data for constructor/destructor lists.

段包含构造/析构列表的数据。

HAS_CONTENTS 

Section is not empty.

段不为空。

NEVER_LOAD 

An instruction to the linker to not output the section.

链接器的指令不输出这一段。

COFF_SHARED_LIBRARY 

A notification to the linker that the section contains COFF shared library information.

告知链接器,段包含共享库的 COFF 信息。

IS_COMMON 

Section contains common symbols.

段包含通用的符号。

set trust-readonly-sections on 

Tell GDB that readonly sections in your object file really are read-only (i.e. that their contents will not change). In that case, GDB can fetch values from these sections out of the object file, rather than from the target program. For some targets (notably embedded ones), this can be a significant enhancement to debugging performance.

告诉 GDB 对象文件中的只读段确实是只读的(他们的内容将不会被改变)。在这种情况下,GDB 可以从对象文件之外的这些段获取变量值,而不是从目标程序。对一些目标(特别是嵌入的),这可能是对调试性能的一个有效的增强。

The default is off.

默认是关闭。

set trust-readonly-sections off Tell GDB not to trust readonly sections. This means that the contents of the section might change while the program is running, and must therefore be fetched from the target when needed.

告知 GDB 不要相信只读段。这意味着段的内容可能在程序执行的过程中被改变,而在需要时必须从目标中获取。

show trust-readonly-sections 

Show the current setting of trusting readonly sections.

显示当前有关 trust-readonly-sections 的设置。

All file-specifying commands allow both absolute and relative file names as arguments. GDB always converts the file name to an absolute file name and remembers it that way.

所有指定文件的命令允许用绝对路径或相对路径作为参数。GDB 总是把他们转换为相对文件名,并且记住他们。

GDB supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix, and IBM RS/6000 AIX shared libraries.

GDB 支持 GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix, 和 IBM RS/6000 AIX 的共享库。

GDB automatically loads symbol definitions from shared libraries when you use the run command, or when you examine a core file. (Before you issue the run command, GDB does not understand references to a function in a shared library, however--unless you are debugging a core file).

GDB 在你使用run 命令或者观察一个core文件的时候,从共享库中自动载入符号的定义(在你执行run 之前,GDB 并不识别共享库中的函数引用,--除非你是在调试一个 core 文件)。

On HP-UX, if the program loads a library explicitly, GDB automatically loads the symbols at the time of the shl_load call.

在 HP-UX 上,如果程序显式地载入一个库,GDB 在shl_load 时自动载入符号。

There are times, however, when you may wish to not automatically load symbol definitions from shared libraries, such as when they are particularly large or there are many of them.

有时候,你并不想自动从共享库中载入符号定义,特别当他们极大或者数量很多的时候。

To control the automatic loading of shared library symbols, use the commands:

控制是否自动载入共享库的符号,使用下面的命令:

set auto-solib-add mode 

If mode is on, symbols from all shared object libraries will be loaded automatically when the inferior begins execution, you attach to an independently started inferior, or when the dynamic linker informs GDB that a new library has been loaded. If mode is off, symbols must be loaded manually, using the sharedlibrary command. The default value is on.

如果 mode 设置为 on,当 inferior 开始执行的时候,或者你附加到一个独立执行的 inferior 上,或者动态链接器通知 GDB 一个新的库被载入,所有共享库中的符号将被自动载入。如果 mode 设置为 off,符号必须被手动载入,使用 sharedlibrary 命令。默认值是 on。

If your program uses lots of shared libraries with debug info that takes large amounts of memory, you can decrease the GDB memory footprint by preventing it from automatically loading the symbols from shared libraries. To that end, type set auto-solib-add off before running the inferior, then load each library whose debug symbols you do need with sharedlibrary regexp, where regexp is a regular expresion that matches the libraries whose symbols you want to be loaded.

如果你的程序使用了很多带有调试信息的共享库,他们占用了很多内存,那么你可以通过禁用自动载入减少 GDB 的内存消耗。要做到这一点,在运行 inferior 之前输入 set auto-solib-add off,然後使用 sharedlibrary regexp(regexp是一个规则表达式,匹配要获取符号的库) 载入你需要调试信息的库。。

show auto-solib-add 

Display the current autoloading mode.

显示当前 autoloading 模式的设置。

To explicitly load shared library symbols, use the sharedlibrary command:

要显式地载入一个共享库的符号,使用 sharedlibrary 命令:

info share 
info sharedlibrary 

Print the names of the shared libraries which are currently loaded.

打印当前载入的共享库的名称。

sharedlibrary regex 
share regex 

Load shared object library symbols for files matching a Unix regular expression. As with files loaded automatically, it only loads shared libraries required by your program for a core file or after typing run. If regex is omitted all shared libraries required by your program are loaded.

载入符合规则表达式的文件的符号。如果是自动载入,那么它仅在输入 run 後或者你的程序请求一个 core 文件时载入共享库。如果 regex 忽略,你的程序需要的所有共享库都被载入。

nosharedlibrary 

Unload all shared object library symbols. This discards all symbols that have been loaded from all shared libraries. Symbols from shared libraries that were loaded by explicit user requests are not discarded.

卸载所有的共享库符号。这一命令放弃所有的从所有的共享库中载入的符号信息。用户明确要求载入的共享库的符号不被放弃。

Sometimes you may wish that GDB stops and gives you control when any of shared library events happen. Use the set stop-on-solib-events command for this:

有时候你可能希望在任何共享库的事件发生时停止 GDB,并给你控制权。请使用 set stop-on-solib-events 命令:

set stop-on-solib-events 

This command controls whether GDB should give you control when the dynamic linker notifies it about some shared library event. The most common event of interest is loading or unloading of a new shared library.

这一命令控制当动态链接器通知了一些共享库事件时,是否让 GDB 把控制权转入你的手里。最常见的事件是载入和卸载一个动态链接库。

show stop-on-solib-events 

Show whether GDB stops and gives you control when shared library events happen.

显示当共享库事件发生时,是否 GDB 停止并把控制权交给你。

Shared libraries are also supported in many cross or remote debugging configurations. A copy of the target's libraries need to be present on the host system; they need to be the same as the target libraries, although the copies on the target can be stripped as long as the copies on the host are not.

共享库在很多交叉和远程调试配置中也是支持的。目标库的一份拷贝需要出现在宿主系统上;他们需要和目标库一样,在这里,目标上的拷贝可以被 strip,而宿主机上的不被 strip。

For remote debugging, you need to tell GDB where the target libraries are, so that it can load the correct copies--otherwise, it may try to load the host's libraries. GDB has two variables to specify the search directories for target libraries.

对远程调试来说,你需要告诉 GDB 目标库所在的地方,这样它才能载入正确的拷贝--不然,它可能试图载入宿主机的库。GDB 有两个指定目标库查找目录的变量。

set solib-absolute-prefix path 

If this variable is set, path will be used as a prefix for any absolute shared library paths; many runtime loaders store the absolute paths to the shared library in the target program's memory. If you use `solib-absolute-prefix' to find shared libraries, they need to be laid out in the same way that they are on the target, with e.g. a `/usr/lib' hierarchy under path. You can set the default value of `solib-absolute-prefix' by using the configure-time `--with-sysroot' option.

如果这一变量被设置,path 将被作为任何绝对路径共享库的前缀;许多运行时的载入器存储目标程序内存中共享库的绝对路径。如果你使用“solib-absolute-prefix”查找共享库,它们应该和目标上有一样的路径结构,比如path下的一个“/usr/lib”的层次。

show solib-absolute-prefix 

Display the current shared library prefix.

显示当前共享库前缀的配置。

set solib-search-path path 

If this variable is set, path is a colon-separated list of directories to search for shared libraries. `solib-search-path' is used after `solib-absolute-prefix' fails to locate the library, or if the path to the library is relative instead of absolute. If you want to use `solib-search-path' instead of `solib-absolute-prefix', be sure to set `solib-absolute-prefix' to a nonexistant directory to prevent GDB from finding your host's libraries.

如果这一变量被设置,其中path 是冒号分割的用来搜索共享库的目录的列表。“solib-search-path”在“solib-absolute-prefix”定位库失败後使用,或者库的路径是相对的,而不是绝对的。如果你想使用“solib-search-path”代替“solib-absolute-prefix”,确定“solib-absolute-prefix”设置的是不存在的目录,以阻止 GDB 查找宿主机上的库。

show solib-search-path 

Display the current shared library search path.

显示当前共享库查找路径的配置。

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值