热门标签 | 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, 如何查看?  的内存地址空间???


推荐阅读
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • 拥抱Android Design Support Library新变化(导航视图、悬浮ActionBar)
    转载请注明明桑AndroidAndroid5.0Loollipop作为Android最重要的版本之一,为我们带来了全新的界面风格和设计语言。看起来很受欢迎࿰ ... [详细]
  • Android源码深入理解JNI技术的概述和应用
    本文介绍了Android源码中的JNI技术,包括概述和应用。JNI是Java Native Interface的缩写,是一种技术,可以实现Java程序调用Native语言写的函数,以及Native程序调用Java层的函数。在Android平台上,JNI充当了连接Java世界和Native世界的桥梁。本文通过分析Android源码中的相关文件和位置,深入探讨了JNI技术在Android开发中的重要性和应用场景。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
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社区 版权所有