热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

gdbmyexperience

1,条件断点(gdb)brEKMemory.cpp:ekmallociftmpsize4760或者(gdb)brEKMemory.cpp:29iftmpsize4760(gdb)i
1, 条件断点


(gdb) br EKMemory.cpp:ekmalloc  if tmpsize == 4760


或者


(gdb) br EKMemory.cpp:29  if tmpsize == 4760




(gdb) info breakpoints 


Num Type           Disp Enb Address    What


2   breakpoint     keep y   0x0041b42e in ekmalloc at src/EKLibrary/EKMemory.cpp:25  stop only if tmpsize == 4760

 

 

 

2,为停止点设定运行命令


br EKMemory.cpp:29  if tmpsize == 4760


commands


bt


continue


end




实例:


(gdb) br EKMemory.cpp:29  if tmpsize == 4760


Breakpoint 1 at 0x41b44a: file src/EKLibrary/EKMemory.cpp, line 29.


(gdb) commands


Type commands for when breakpoint 1 is hit, one per line.


End with a line saying just "end".


>bt


>continue


>end


(gdb) c


Continuing.




Breakpoint 1, ekmalloc (size=4760) at src/EKLibrary/EKMemory.cpp:29


29      src/EKLibrary/EKMemory.cpp: No such file or directory.


in src/EKLibrary/EKMemory.cpp


#0  ekmalloc (size=4760) at src/EKLibrary/EKMemory.cpp:29


#1  0x0041b520 in ekioh::EKMemory::alloc (size=4760) at src/EKLibrary/EKMemory.cpp:169


#2  0x0041b5ac in operator new[] (size=4760) at src/EKLibrary/EKMemory.cpp:151


#3  0x00497f0e in ekioh::KreaTvGfxPixMap::create (width=14, height=85) at src/Platform/Motorola/KreaTvGfx/KreaTvGfxPixMap.cpp:161


#4  0x00499d14 in ekioh::KreaTvGfxPlatform::createPixMap (this=0x7be854c0, width=14, height=85, bpp=32 ' ')


at src/Platform/Motorola/KreaTvGfx/KreaTvGfxPlatform.cpp:150


#5  0x004434dc in ekioh::EKGContext::createPixMap (width=14, height=85, bpp=32 ' ', accelerated=false) at src/EKLibrary/Graphics/EKGContext.cpp:291


#6  0x2a722e1c in WebCore::ImageSource::createFrameAtIndex () from /usr/lib/libekioh_adapt_webkit525-kreatvgfx.so


#7  0x2a4a9ea0 in WebCore::BitmapImage::cacheFrame () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#8  0x2a4aa996 in WebCore::BitmapImage::frameAtIndex () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#9  0x2a4abbb0 in WebCore::BitmapImage::nativeImageForCurrentFrame () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#10 0x2a4c5062 in WebCore::Image::drawTiled () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#11 0x2a4bef74 in WebCore::GraphicsContext::drawTiledImage () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#12 0x2a54421c in WebCore::RenderBox::paintBackgroundExtended () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#13 0x2a5395cc in WebCore::RenderBox::paintBackground () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#14 0x2a5396a2 in WebCore::RenderBox::paintBackgrounds () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#15 0x2a5453da in WebCore::RenderBox::paintBoxDecorations () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#16 0x2a5305fc in WebCore::RenderBlock::paintObject () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#17 0x2a52a566 in WebCore::RenderBlock::paint () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#18 0x2a57669a in WebCore::RenderLayer::paintLayer () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#19 0x2a576cd0 in WebCore::RenderLayer::paintLayer () from /usr/lib/libekioh_webcore_webkit525-kreatvgfx.so


#20 0x2ce1a510 in ?? ()


#21 0x2ce1a510 in ?? ()


Previous frame identical to this frame (corrupt stack?)






3,调试运行中程序


gdb -p PID


(gdb) breakpoints EKMemory.cpp:29  if tmpsize == 4760


(gdb) c

 

 

4 gdb 查看core dump ;

 

4.1. 前言:
有的程序可以通过编译, 但在运行时会出现Segment fault(段错误). 这通常都是指针错误引起的.
但这不像编译错误一样会提示到文件->行, 而是没有任何信息, 使得我们的调试变得困难起来.

4.2. gdb:
有一种办法是, 我们用gdb的step, 一步一步寻找.
这放在短小的代码中是可行的, 但要让你step一个上万行的代码, 我想你会从此厌恶程序员这个名字, 而把他叫做调试员.
我们还有更好的办法, 这就是core file.

4.3. ulimit:
如果想让系统在信号中断造成的错误时产生core文件, 我们需要在shell中按如下设置:
#设置core大小为无限
ulimit -c unlimited
#设置文件大小为无限
ulimit unlimited

这些需要有root权限, 在ubuntu下每次重新打开中断都需要重新输入上面的第一条命令, 来设置core大小为无限.

4.4. 用gdb查看core文件:
下面我们可以在发生运行时信号引起的错误时发生core dump了.
发生core dump之后, 用gdb进行查看core文件的内容, 以定位文件中引发core dump的行.
gdb [exec file] [core file]
如:
gdb ./test test.core
在进入gdb后, 用bt命令查看backtrace以检查发生程序运行到哪里, 来定位core dump的文件->行.

4.5. 用gdb实时观察某进程crash信息
启动进程
gdb -p PID
c
运行进程至crash
gdb会显示 crash信息
bt

 

 

 

5, gdb used on kreatv:

his is a tip about how to use gdb to check the crash bug:

5.1  . add "kreatv-tool-gdb" to bootimage
5.2. use kernel+nfs to boot up the box.
5.2.1 copy the execute file and .so lib into rootdisk's related position. 
[leo@leo dlnamediacontroller]$ sudo cp st40/dlnamediacontroller /opt/nfs/rootdisk/usr/bin/dlnamediacontroller
[leo@leo dlnamediacontroller]$ pwd
/mnt/sda5/mot_develop/BRASSICA/platform/dlnamediacontroller


5.3. update the rootdisk/usr/bin/start_platform.sh to enable the core dump.
export COREDUMP_ENABLED=yes


5.4. when crash happens, core dump files are stored in the box's / directory. For example core.1167 which means the core dump file is created by the process pid 1167 5. telnet to the box and use gdb to check the core dump. For example, if the streamer crash and the pid is 574, run gdb like this:

The following can use box or PC.  It is better run in box which need add "kreatv-tool-gdb" to bootimage.
# gdb /usr/bin/streamer core.574


5.6. If you are luck, you can see  the streamercrashat which function and which line.

5.7. Most of time, you are not luck, you only can see some  information like this:
#0  0x298ae0a4 in ?? ()
(gdb)bt
#0  0x298ae0a4 in ?? ()
#1  0x298af5a0 in ?? ()
This is because most of our binary and library are strippedbefore copying the the rootdisk.  
Replacing the binary or library in the rootdisk with the original one built from branch and test again! Then you can see the detail function name.

It is proved very useful to fix some kinds of crash bug.





How can we crash process or box?
assert(1==0);  will trige it.
int a = 1/0;  will trige it.
char *abcd;
memcpy(abcd, "12345678",8); will trige it.



How to analyze core dump
• Run gdb in box
• or Run arm-kreatel-linux-gnu-gdb in PC
• Command example
   – #xxx_gdb /usr/bin/streamer -c /tmp/core.dump
   – #bt


Readme:
a, kreatv-tool-gdb  only decide whether you can telnet box,and gdb on box.

 

example: 

 /# gdb /usr/applications/ekioh/ekioh  core.526
GNU gdb 6.5-ST-1.0-ST40 [build Jul  2 2009]
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sh4-motorola-linux-gnu"...(no debugging symbols found)
Using host libthread_db library "/lib/libthread_db.so.1".

warning: Can't read pathname for load map: Input/output error.
Reading symbols from /usr/lib/libVirtualDisplay.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libVirtualDisplay.so


Loaded symbols for usr/browser/plugins/libmotorolatoi.so
Got object file from memory but can't read symbols: File format not recognized.

Core was generated by `/usr/applications/ekioh/ekioh --cache 0 --url http://192.168.5.215'.
Program terminated with signal 7, Bus error.
#0  0x29f3224c in KJS::Bindings::Instance::setValueOfField () from /usr/lib/libJavascriptcore.so


(gdb) bt
#0  0x29f3224c in KJS::Bindings::Instance::setValueOfField () from /usr/lib/libJavascriptcore.so
#1  0x29919512 in ekioh::GTKSocketCollection::callback (source=, condition=2076097000, data=0x443b50)
    at src/Platform/GTK/GTKSocketCollection.cpp:255
#2  0x2a5ebbf2 in g_io_add_watch () from /usr/lib/libglib-1.2.so.0
#3  0x2a5ecdb2 in g_main_add_poll () from /usr/lib/libglib-1.2.so.0
#4  0x2a60875c in ?? () from /usr/lib/libglib-1.2.so.0
#5  0x2a60875c in ?? () from /usr/lib/libglib-1.2.so.0
Previous frame identical to this frame (corrupt stack?)

(gdb) q
/ # exit
Connection closed by foreign host.
[root@localhost infocast]#

 

6, 如何查看?  的内存地址空间???


推荐阅读
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 如何在服务器主机上实现文件共享的方法和工具
    本文介绍了在服务器主机上实现文件共享的方法和工具,包括Linux主机和Windows主机的文件传输方式,Web运维和FTP/SFTP客户端运维两种方式,以及使用WinSCP工具将文件上传至Linux云服务器的操作方法。此外,还介绍了在迁移过程中需要安装迁移Agent并输入目的端服务器所在华为云的AK/SK,以及主机迁移服务会收集的源端服务器信息。 ... [详细]
  • 利用Visual Basic开发SAP接口程序初探的方法与原理
    本文介绍了利用Visual Basic开发SAP接口程序的方法与原理,以及SAP R/3系统的特点和二次开发平台ABAP的使用。通过程序接口自动读取SAP R/3的数据表或视图,在外部进行处理和利用水晶报表等工具生成符合中国人习惯的报表样式。具体介绍了RFC调用的原理和模型,并强调本文主要不讨论SAP R/3函数的开发,而是针对使用SAP的公司的非ABAP开发人员提供了初步的接口程序开发指导。 ... [详细]
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • 本文介绍了C#中生成随机数的三种方法,并分析了其中存在的问题。首先介绍了使用Random类生成随机数的默认方法,但在高并发情况下可能会出现重复的情况。接着通过循环生成了一系列随机数,进一步突显了这个问题。文章指出,随机数生成在任何编程语言中都是必备的功能,但Random类生成的随机数并不可靠。最后,提出了需要寻找其他可靠的随机数生成方法的建议。 ... [详细]
  • Voicewo在线语音识别转换jQuery插件的特点和示例
    本文介绍了一款名为Voicewo的在线语音识别转换jQuery插件,该插件具有快速、架构、风格、扩展和兼容等特点,适合在互联网应用中使用。同时还提供了一个快速示例供开发人员参考。 ... [详细]
  • 计算机存储系统的层次结构及其优势
    本文介绍了计算机存储系统的层次结构,包括高速缓存、主存储器和辅助存储器三个层次。通过分层存储数据可以提高程序的执行效率。计算机存储系统的层次结构将各种不同存储容量、存取速度和价格的存储器有机组合成整体,形成可寻址存储空间比主存储器空间大得多的存储整体。由于辅助存储器容量大、价格低,使得整体存储系统的平均价格降低。同时,高速缓存的存取速度可以和CPU的工作速度相匹配,进一步提高程序执行效率。 ... [详细]
  • Webmin远程命令执行漏洞复现及防护方法
    本文介绍了Webmin远程命令执行漏洞CVE-2019-15107的漏洞详情和复现方法,同时提供了防护方法。漏洞存在于Webmin的找回密码页面中,攻击者无需权限即可注入命令并执行任意系统命令。文章还提供了相关参考链接和搭建靶场的步骤。此外,还指出了参考链接中的数据包不准确的问题,并解释了漏洞触发的条件。最后,给出了防护方法以避免受到该漏洞的攻击。 ... [详细]
  • 加密世界下一个主流叙事领域:L2、跨链桥、GameFi等
    本文介绍了加密世界下一个主流叙事的七个潜力领域,包括L2、跨链桥、GameFi等。L2作为以太坊的二层解决方案,在过去一年取得了巨大成功,跨链桥和互操作性是多链Web3中最重要的因素。去中心化的数据存储领域也具有巨大潜力,未来云存储市场有望达到1500亿美元。DAO和社交代币将成为购买和控制现实世界资产的重要方式,而GameFi作为数字资产在高收入游戏中的应用有望推动数字资产走向主流。衍生品市场也在不断发展壮大。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • 本文介绍了Windows操作系统的版本及其特点,包括Windows 7系统的6个版本:Starter、Home Basic、Home Premium、Professional、Enterprise、Ultimate。Windows操作系统是微软公司研发的一套操作系统,具有人机操作性优异、支持的应用软件较多、对硬件支持良好等优点。Windows 7 Starter是功能最少的版本,缺乏Aero特效功能,没有64位支持,最初设计不能同时运行三个以上应用程序。 ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
author-avatar
陈陈
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有