GDB调试技巧
1. GDB 调试程序
1.Run a program without any argument.
gdb program
2. Run a program with arguments
gdb --args program arg1 arg2 ... argN
or
gdb program
(gdb) r arg1 arg2 ... argN
3. start with both an executable program and a core file specified
gdb program core
(gcore file: Produce a Core File from Your Program)
4. debug a running process,
specify a process ID as a second argument or use option –p
the following would attach gdb to process 1234:
gdb program 1234
gdb –p 1234
2. 常用命令
r - (run)Runs the program until a breakpoint or error
c - (continue) Continues running the program until the next breakpoint or error
fin – (finish) Continue running until just after function in the selected stack frame returns . 直接运行至当前函数结束,比如误按s进入函数A,在函数A中输入fin会直接跳出函数A.
ret – (return)Returns from current function; 直接退出当前函数,函数内尚未运行的code不会被执行。
j location – (jump) Resume execution at location; it does not change the current stack frame, like run(set $pc = location)
s - (step) Runs the next line of the program (step into)
s N - Continue running as in step, but do so N times
n – (next) Like s, but it does not step into functions
n N - Continue to the next source N line in the current (innermost) stack frame
p expr - (print) Prints the current value of the variable “expr“
p/f expr - you can choose a different format by specifying ‘/f’, where f is a letter specifying the format。比如p/x expr: 会以16进制的格式打印出expr
bt - (backtrace) Prints a stack trace
bt full N - Print the values of the local variables also of the innermost N frames. 加上full会打印出每个frame的局部变量。N指示打印出几级frame.
u - (until) This command is used to avoid single stepping through a loop more than once. u 经常用于跳出当前循环。
u N - Continue running your program until either the specified location is reached, u 123: 会直接运行到123行code.
or the current stack frame returns
f - (frame) print current stack frame info.
up n - Move n frames up the stack; n defaults to 1. 显示上面的第几级的frame的code,注意:只是显示code, pc并没有发送变化,即程序并没有执行。
down n -Move n frames down the stack; n defaults to 1.
q - (quit) Quits gdb
b – (breakpoint) Set breakpoint (see next page)
3. 设置断点-breakpoint
Break into a Function
(gdb) b function
Break into a Function in a given file
(gdb) b filename:function
Break on to a line in a given file
(gdb) b filename:linenum
Break upon matching memory address
(gdb) b *(memory address)
Set a breakpoint with condition cond
(gdb) b <...> if condition
condition bnum experssion
# Note:
#1: The symbol <...> implies that you can use any form of breakpoints.
Example: break linenum if variable==1
Others:
b N - Puts a breakpoint at line N
b - Puts a breakpoint at the current line ,当前行设置断点。
b+N - Puts a breakpoint N lines down from the current line
# Note: Break will take place at line in the current source file.
# The current file is the last file whose code appeared in the debug console.
i b – show all breakpoints
d – delete all breakpoints, 删除所有断点(不用担心,会有二次确认删除提示)。
d n – delete specified(n- breakpoints are numbered when created) breakpoint
dis n – disable specified(n) breakpoint , 去能断点
ena n – enable specified(n) breakpoint, 使能断点。
tb - set temporary breakpoint ,设置临时断点,只作用一次,自动删除。
rb regex - set breakpoints on all functions matching the regular expression regex(grep rule), 设置一类函数断点,函数名符合一定的正则表达式即可。
commands n: You can give any breakpoint a series of commands to execute
when your program stops due to that breakpoint, 每一个断点可以设置对应的命令,断点触发后,这些命令会被自动运行。
save b [filename] : saves all current breakpoint to a file. 在gdb退出之前,可以存储目前断点的信息,以便下次调试时重新加载。
source [filename]: restore breakpoints
4. 设置观察点-watchpoint
Set a watchpoint for an expression. gdb will break when the expression expr is written into by the program and its value changes. The simplest (and the most popular) use of this command is to watch the value of a single variable:
(gdb) watch drbId
If you watch for a change in a numerically entered address you need to dereference it, as the address itself is just a constant number which will never change. gdb refuses to create a watchpoint that watches a never-changing value:
(gdb) watch 0x600850
Cannot watch constant value 0x600850.
(gdb) watch *(int *) 0x600850
Watchpoint 1: *(int *) 6293584
watch – write watchpoint , 写观察点, 当观察点的值被修改时触发。
rwatch – read watchpoint, 读观察点, 当观察点的值被读取时触发。
awatch – access watchpoint, 访问(读写)观察点, 被修改或被读取时均会触发。
备注,观察点与硬件中断有关,不能设置的太多。
比如一个struct A, 里面有200个不同类型的数据, 有全局变量 A a, 如果设置 watch a, 会报错,提示: 观察点太多。不同的硬件平台,最多设置观察点的个数不尽相同。另外,如果给局部变量设置 b 一个观察点,则在b作用域失效后,其对应的观察点自动失效。
5. 设置检查点-checkpoint
checkpoint:
Save a snapshot of the debugged program’s current execution state
restart checkpoint-id
Restore the program state that was saved as checkpoint number checkpoint-id
checkpoint 可以保存程序某一时刻的状态信息,用于后续恢复这一时刻。比如,一个很难复现的bug,你费了九牛二虎之力终于复现了,你就可以保存这一检查点,继续调试,如果调试期间错过了某些信息,需要重新调试,你就可以恢复之前保存的观察点,反复调试,犹如时光倒流。
6. 检查变量和设置变量
p x : Prints current value of variable x.
display x: Constantly displays the value of variable x, which is shown after every step or pause. 程序没运行一次,都会打印此变量的值。
undispaly x: Removes the constant display
whatis x: Print the data type of x, 查看变量的类型
info locals: Print the local variables of the selected frame, 打印当前的堆栈局部变量。
info variables: All global and static variable names, or those matching REGEXP,显示全局变量和静态变量名。也可以模糊匹配,比如:info variables g*: 会显示g开头的全局变量和静态变量名
set x=3 : sets x to a set value (3) , 程序运行时,可以修改变量的值。
x/FMT ADDRESS: Examine memory, 检查内存的值,非常有用。
FMT is a repeat count followed by a format letter and a size letter.
Format letters are : o(octal), x(hex), d(decimal), u(unsigned decimal), t(binary), f(float), a(address),
i(instruction), c(char) and s(string).
Size letters are: b(byte), h(halfword), w(word), g(giant, 8 bytes)
7. 调用程序和CRT
在gdb 调试时,可以在cmd窗口直接调用工程中过的函数和c 语言标准库。
call function()
call function(x)
call strlen(x)
call sizeof(x)
8. 调试log输出
如果我们要打印的变量结构体非常庞大,这时我们可以将此变量的值保存到文件中,单独打开保存的文件以便更容易查看、。
show logging
Show the current values of the logging settings.
set logging on
Enable logging.
set logging off
Disable logging.
set logging file file
Change the name of the current logfile. The default logfile is gdb.txt.
set logging overwrite [on|off]
By default, gdb will append to the logfile. Set overwrite if you want set logging on to overwrite the logfile instead
9.生成Core File
A core file or core dump is a file that records the memory image of a running process and its process status (register values etc.).
generate-core-file [file] : 生成core file. note: 缩写:gcore [file]
gdb exe_name core.file : gdb 加载core file, exe_name 为可执行文件的名字。
相关文章:

php 进程管理,php如何管理进程
进程管理-防止进程成为僵尸进程创建好了进程,那么怎么对子进程进行管理呢?使用信号,对子进程的管理,一般有两种情况:(推荐学习:PHP编程从入门到精通)posix_kill():此函数并不能顾名思义…

Linux分区的认识
有时候为了便于管理硬盘或允许在一块硬盘上使用多个文件系统或操作系统,需要对硬盘进行分区操作。硬盘的分区分为3种:主分区、扩展分区、逻辑分区。通常因为计算机BIOS和MBR的限制,一块硬盘最多只能有4个分区,其中一个主分区可用扩…

求小数的小数点的第n位是什么
链接:https://ac.nowcoder.com/acm/contest/548/B来源:牛客网 时间限制:C/C 1秒,其他语言2秒空间限制:C/C 262144K,其他语言524288K64bit IO Format: %lld题目描述 立华奏在学习初中数学的时候遇到了这样一…

Git 简介1-常用术语
常用术语 1. origin origin是对项目最初克隆(clone)的远程仓库的缩写。 更准确地说,origin 是用来代替原始(original)远程仓库的URL, 从而使在git 命令中使用原始仓库更加容易。 2. master master 是分支的命名约定。 从远程服务器克隆后,生成的本…

要过一遍的博客列表
面向GC的Java编程 (finish) java程序员也应该知道的系统知识系列 (finish) 一致性哈希算法及其在分布式系统中的应用(finish) NoSQL数据库的分布式算法 深入理解java内存模型系列文章 转载于:https://www.cnblogs.com/dongxiao-yang/p/4767179.html

b站弹幕 xml php 乱码,B站弹幕Python爬行XML响应中的代码转换问题,python,之,取,b,xml,时,转码...
在学习过程中,可以发现,对于xml类型的响应,了解到的方式lxml和bs解析器。frombs4importBeautifulSoup #主要使用BeautifulSoup类事实上可以认为:HTML文档和标签树,BeautifulSoup类是等价的Beautiful Soup库解析器&…

java.io包和杯子测楼
1 java.io 字符流:Reader 字节流:InputStream 2 杯子测楼 一种杯子,若在第N层被摔破,则在任何比N高的楼层均会破,若在第M层不破,则在任何比M低的楼层均不会破,给你两个这样的杯子,让…

JUnit测试类完成后事务是默认 回滚的。只能查询数据,不能增删改。
JUnit测试类完成后事务是默认 回滚的。只能查询数据,不能增删改。 在测试类或者测试方法上面加上注解 Rollback(false) 表示事物不回滚,这样数据就可以提交到数据库中了。 转载于:https://www.cnblogs.com/zhangcheng1/p/11156389.html

gcc 编译选项
下载gcc文档,第三章有详细的build options的介绍。 最近我用到2个关键的option 来定位问题,简单介绍一下: 1. -E: 只是进行预编译,不会编译和link。用于检查宏在代码中的展开是否符合预期; 2.--verbose: 开启verbos…

ionic中的后退方法
1)$ionicHistory.goBack();2)$ionicNavBarDelegate.back(); 个人感觉: 1)$ionicHistory.goBack()会按照html历史来后退 2)$ionicNavBarDelegate.back()会按照ion-nav-view的层级来跳转;但是,调用…

php 生成非对称密钥,php实现非对称加密
使用非对称加密主要是借助openssl的公钥和私钥,用公钥加密私钥解密,或者私钥加密公钥解密。1.安装openssl和PHP的openssl扩展2.生成私钥:openssl genrsa用于生成rsa私钥文件,生成是可以指定私钥长度和密码保护1. openssl genrsa -…

HDU 4951 Multiplication table(2014 Multi-University Training Contest 8)
思路 如果进制为p 那么当x<p时 (p-1)*(p-x)(p-(x1)) *p x 因为x<p 所以没有进位 所以高位上的数字为 p-(x1)。 根据上面所述。 只要我们能找出 p-1 那么我们…

H3C 静态默认路由配置
转载于:https://www.cnblogs.com/fanweisheng/p/11156783.html

malloc为什么会报错:memory corruption
最近遇到一个问题,很有意思,在此记录下,以备后续参考。 程序运行异常,报错:malloc: memory corruption. 用gdb 调试程序,bt 如下,程序在申请344 bytes内存时失败。 疑问:344bytes内…

php 静态类内存,php面向对象中static静态属性与方法的内存位置分析
本文实例分析了php面向对象中static静态属性与方法的内存位置。分享给大家供大家参考。具体如下:static静态属性的内存位置——>类,而不是对象。下面做测试来证明一下header("content-type:text/html;charsetutf-8");class Human{static pu…

Android中实现为TextView添加多个可点击的文本
这篇文章主要介绍了Android中实现为TextView添加多个可点击的文本,可实现类似Android社交软件显示点赞用户并通过用户名称进入该用户主页的功能,是非常实用的技巧,需要的朋友可以参考下。具体如下: 很多时候我们在使用社交软件的过程中多多少少会为别人的帖子点赞&a…

Set和存储顺序深入探讨、SortedSet排序的示例
2019独角兽企业重金招聘Python工程师标准>>> Set和存储顺序深入探讨、SortedSet排序的示例 package org.rui.collection2.set;import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; import java.util.TreeSet;//TypesForSets.java /**…

设计模式七大原则(C++描述)
前言 最近在学习一些基本的设计模式,发现很多博客都是写了六个原则,但我认为有7个原则,并且我认为在编码中思想还是挺重要,所以写下一篇博客来总结下 之后有机会会写下一些设计模式的博客(咕咕咕........ 设计模式的七大原则 1.单一职责原则 2.开放-封闭原则 3.依赖倒置原则 4.…

gdb高级调试技巧
1. 反向调试 gdb支持程序反向执行。 record 让程序开始记录反向调试所必要的信息 rn : reverse next rc: reverse continue ,Continue program being debugged but run it in reverse record stop: 停止记录 2. 格式化(pretty print)打…

php代码实现关键词搜索,PHP代码实现百度统计关键词及来路推送
搜索热词勾起我搞这个的兴趣是因为有个卖软件的,老是向我的百度统计后台推送引流软件广告。搜索后发现早就有人做过这方面的研究,然而随着统计代码版本升级,部分功能暂时还未解决。今天这篇 PHP 代码实现提交虚假数据给百度统计就教大家&…

linux跨主机复制文件
scp -r billing10.200.171.111:/billdata2/user/yanhm/redis/* /newboss/billing/user/aabb 其中: 10.200.171.111:远程主机 billing:远程主机的用户名 /billdata2/user/yanhm/redis/:要复制远程主机的文件路径 /newboss/billing/…

delphi使用outputdebugstring调试程序和写系统日志
delphi使用outputdebugstring调试程序和写系统日志 procedure TForm1.btn1Click(Sender: TObject); beginOutputDebugString(dddddd);OutputDebugString(11); end;procedure TForm1.btn2Click(Sender: TObject); varEvtSrcHand: THandle;EvtMsg: String; p:Pointer; i:integer;…

一个下载Windows镜像的地址
https://www.52pojie.cn/thread-633128-1-1.html转载于:https://www.cnblogs.com/blogs-jch/p/11163849.html

perf + 火焰图分析程序性能
From: https://www.cnblogs.com/happyliu/p/6142929.html 1、perf命令简要介绍 性能调优时,我们通常需要分析查找到程序百分比高的热点代码片段,这便需要使用 perf record 记录单个函数级别的统计信息,并使用 perf report 来显示统计结果&a…

jquery 设置css样式
$("#61dh a").css(color, 多个样式属性 var divcss {background: #EEE,width: 478px,margin: 10px 0 0,padding: 5px 10px,border: 1px solid #CCC};$("#result").css(divcss);查看某个元素的css属性值。 $("#61dh a").css("color"…

php改7z,PHP的7z扩展名? - php
我找不到一个,也不知道PHP Compression and Archive Extensions中的任何一个是否可以工作。您认为我可以使用compression stream从7z文件读取数据吗?更新7z forums对php扩展有很多要求参考方案7z文件格式可以使用各种compression algorithms,…

Classloader内存泄露
2019独角兽企业重金招聘Python工程师标准>>> 最近遇到了这个问题,在修改了-Xmx后有时仍然会出现,下文分析的很有启发,看了下文重新分析我的应用,在项目中我使用了spring mvc作为控制层,由于使用到了微信公众…

Springboot + oauth2 单点登录 - 原理篇
OAuth 协议为用户资源的授权提供了一个安全的、开放而又简易的标准,允许用户授权第三方移动应用访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方移动应用或分享他们数据的所有内容,OAuth2.0是OAuth协议的延续版本,但不向后兼容OAuth 1.0即完全废止了OAuth1.0。授权码模式(authorization code)密码模式(resource owner password credentials)客户端模式(client credentials) 不常用。

Java 类型判断方法
Java 类型判断方法有三种,分别是instanceof是关键字,isInstance和isAssignableFrom是Class中的方法。> cls);

Docker-Compose搭建单体SkyWalking 6.2
SkyWalking简介 SkyWalking是一款高效的分布式链路追踪框架,对于处理分布式的调用链路的问题定位上有很大帮助 有以下特点: 性能好 针对单实例5000tps的应用,在全量采集的情况下,只增加 10% 的CPU开销。支持多语言探针支持自动及手…