A few gdb debug articles

Source: Internet
Author: User

Http://hi.baidu.com/janvyking999/blog/item/6697b43ac79672e315cecb5f.html

Useful for:

View Current source program
Info source

5 Conditional breakpoints
Break ... if cond

==,>= usage and C are the same, don't write =

Info B is where all breakpoints are displayed

Set up a watch = = = Watch
When you are debugging a very large program, and you are tracking a key variable, you find that the variable is not known where it was changed and how to find the place to change it. You can then use the Watch command. Simply put, a watch can let you monitor an expression or variable when it is read or written.
Program
Broken down. The usage of the Watch command is as follows:
Watch expression
Watch instructions are written, and when you want to monitor an expression or variable being read, you need to use the Rwatch directive, which is exactly the same. It is important to note that the monitoring point has both hardware and software, and if possible Linux is as hardware as possible, because the hardware is much faster than the software way. Software mode because you want to check whether the value you want to monitor is changed after each execution of an instruction, it can be executed much less quickly. At the same time it cannot be set to be read when the
Program
Because the read operation does not change the value, GDB cannot detect the read operation. Fortunately, the current PC basically supports the hardware approach. If you want to make sure that your machine supports hardware, you can set a watch with watch when you debug the program, if GDB shows you:
Hardware Watchpoint num:expr

The Whatis command can display the type of a variable

Http://hi.baidu.com/beyond907/blog/item/c7f9a3f538da3dd2f3d3856e.html

1, program operation parameters.
Set args can specify runtime parameters. (Example: Set args 10 20 30 40 50)
The show args command can view the set run parameters.

2, the operating environment.
Path <dir> can set the running paths of the program.
Show paths view the running path of the program.
Set environment VarName [=value] Sets the environment variable. such as: Set env User=hchen
Show environment [varname] View environment variables.

3, working directory.
CD <dir> equivalent to the Shell's CD command.
The PWD displays the current directory.

Until or U
When you're tired of stepping through a loop, this command can run the program until you exit the loop body.

Info Threads Show All threads

Break frik.c:13 thread Bartab > Lim
If it is a thread pool, you can define a breakpoint to be added in line Line 28.

We can use the command command provided by GDB to set the run of the stop point. In other words, when the running program is stopped, we can let it run some other commands automatically, which is very advantageous for automated debugging. is a powerful support for GDB-based automated debugging.
Break Foo if x>0
Commands
printf "x is%d\n", X
Continue
End

You want to print stack information for all threads at a breakpoint, and do not know how to set
Later found the statement: thread apply all BackTrace

Http://hi.baidu.com/beyond907/blog/item/10c86e0150ff658ce850cd6f.html

Forward-search <regexp>
Search <regexp>
Search the front.

Reverse-search <regexp>
Search all.

(GDB) p *[email protected]
$ = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40}

You can set up some automatically displayed variables that are automatically displayed when the program stops, or when you step through the tracks. The associated GDB command is display.

Display <expr>
Undisplay <dnums...>
Delete Display <dnums...>
Remove Auto Display

modifying variable values in a program set VAR width=47

Http://www.linuxforum.net/forum/gshowflat.php?Cat=&Board=program&Number=692404&page=0&view=collapsed

Info threads
Displays all threads currently available for debugging, each of which has a GDB-assigned ID, which is used when the thread is later manipulated.
Previous * is the thread that is currently being debugged.

Thread ID
Toggles the thread of the currently debugged thread to the specified ID.

Thread Apply ID1 ID2 command
Have one or more threads execute GDB command commands.

Thread apply all command (e.g. B apply all BT view all stacks)
Let all the debugged threads execute the GDB command.

Set Scheduler-locking Off|on|step
It is estimated that people who have actually used multi-threaded debugging can find that when using the step or the continue command to debug the currently debugged thread, the other threads are executed simultaneously, how to only let the debug program execute it? This requirement can be achieved with this command.
Off does not lock any threads, that is, all threads are executed, which is the default value.
On only the currently debugged program will execute.
Step in a single step, in addition to the case of next over a function (the person familiar with the situation may know that this is actually a set breakpoint and then continue behavior), only when the front-thread will execute.

=========================

Unfortunately, the URL of Baidu space is not open.


View memory with GDB

Format: X/nfu <addr>

Description
X is the abbreviation of examine

n indicates the number of memory units to display

F represents the display mode, the following values are preferable
x Displays the variable in hexadecimal format.
D Displays the variable in decimal format.
u displays unsigned integers in decimal format.
o Displays the variable in octal format.
T displays the variable in binary format.
A displays the variable in hexadecimal format.
I instruction address format
C Displays the variable in character format.
F Displays the variable in floating-point number format.

U represents the length of an address unit
b represents a single byte,
H represents double-byte,
W represents four bytes,
g = Eight bytes


Format Letters is O (octal), X (hex), D (decimal), U (unsigned decimal),
T (binary), F (float), a (address), I (instruction), C (char) and S (String).
Size Letters is B (byte), H (Halfword), W (word), G (Giant, 8 bytes)

Example
X/3xh BUF
Indicates that the contents are read from the memory address buf.
H represents a unit in double-byte,
3 means three units,
x indicates hexadecimal display


This article is from "Flying Justice Blog" blog, please be sure to keep this source http://xzq2000.blog.51cto.com/2487359/1766862

A few gdb debug articles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.