Embedded Linux Core Dump 调试方法

在为嵌入式打开Core Dump的时候遇到了一开始想不到的问题,挺有意思

大多数论坛里说的打开Core Dump的方法就是按照如下几个步骤就能实现

1. 在make menuconfig里打开core dump选项

    Userspace binary formats --> Enable core dump support

    General setup --> Configure standard kernel features --> Enable ELF core dumps

2. 程序运行前执行 ulimit -c unlimited,在检查ulimit -c确认开启成功

正常pc机在程序这两步就能产生core文件

 

笔者的挂死的进程有此特点:在rcS.d的脚本以后台方式运行进程

按照以上打开core dump的说明,在ulimit -c确认时获得返回值为0

查到在下列条件下不产生core文件:
( a )进程是设置-用户-ID,而且当前用户并非程序文件的所有者;
( b )进程是设置-组-ID,而且当前用户并非该程序文件的组所有者;
( c )用户没有写当前工作目录的许可权;
( d )文件太大。core文件的许可权(假定该文件在此之前并不存在)通常是用户读/写,组读和其他读。

先为所有终端环境都开启ulimit -c unlimited,在/etc/profile文件加入ulimit -c unlimited

掉电上电,此时ulimit -c可确认core dump已经打开,在终端里运行一场程序,产生了core dump

但是笔者的在rcS.d的脚本以后台方式运行进程异常死掉,依然没有core dump

再满足(a)(b),因为我们知道我们查看core文件是在root用户下查看的,所以在rc5.d的脚本中使用指定的用户来执行命令

su - root -c "/usr/bin/msgdeliver &"

放后台也会脱离终端导致不产生core dump,所以就做重定向core文件

echo "/data/core.%e.%t.%p" > /proc/sys/kernel/core_pattern

然后core.msgdeliver.xxx.xxx就糊里糊涂的出来了

 

 

查到一段,ulimit作用范围的描述

1. 能够影响ulimit的参数会有这几个文件,除了/etc/profile,/etc/init.d/functions, /etc/security/limits.conf几个系统默认文件外,以及任何写入的ulimit命令的脚本,如用户目录下的. bash_profile文件。
2. ulimit是随着进程的启动而生效的,它只能影响当前父进程以及由它衍生出来的子进程,一旦父进程结束,ulimit的值就将使用系统默认值。
3. 进程启动所获得的ulimit值与用户登录进去用ulimit -a所查看的值是两个概念。这一点可能不太明白,因为linux启动的时候会启动init这个程序,调用inittab ->rc.sysinit->rcx.d->rc.local->minigetty开始侦听,因此进程启动时的ulimit只 是在rcx.d下的启动脚本中设置,并在进程中继承,而用户登录系统时,会去读取/etc/profile配置文件,因而无关,这就是为什么那么多人迷惑 的地方。

 

 

未完待续...

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Key Features, Create efficient and secure embedded devices using LinuxMinimize project costs by using open source tools and programsExplore each component technology in depth, using sample implementations as a guide, Book Description, Mastering Embedded Linux Programming takes you through the product cycle and gives you an in-depth description of the components and options that are available at each stage. You will begin by learning about toolchains, bootloaders, the Linux kernel, and how to configure a root filesystem to create a basic working device. You will then learn how to use the two most commonly used build systems, Buildroot and Yocto, to speed up and simplify the development process. Building on this solid base, the next section considers how to make best use of raw NAND/NOR flash memory and managed flash eMMC chips, including mechanisms for increasing the lifetime of the devices and to perform reliable in-field updates. Next, you need to consider what techniques are best suited to writing applications for your device. We will then see how functions are split between processes and the usage of POSIX threads, which have a big impact on the responsiveness and performance of the final device The closing sections look at the techniques available to developers for profiling and tracing applications and kernel code using perf and ftrace., What you will learn, Understand the role of the Linux kernel and select an appropriate role for your applicationUse Buildroot and Yocto to create embedded Linux systems quickly and efficientlyCreate customized bootloaders using U-BootEmploy perf and ftrace to identify performance bottlenecksUnderstand device trees and make changes to accommodate new hardware on your deviceWrite applications that interact with Linux device driversDesign and write multi-threaded applications using POSIX threadsMeasure real-time latencies and tune the Linux kernel to minimize them, About the Author, Chris Simmonds is a software consultant and trainer who lives in southern England. He has been using Linux in embedded systems since the late 1990s, during which he has worked on many interesting projects, including a stereoscopic camera, intelligent weighing scales, various set-top boxes and home routers, and even a large walking robot., He is a frequent presenter at open source and embedded conferences, including the Embedded Linux Conference, Embedded World, and the Android Builders' Summit. He has been conducting training courses and workshops in embedded Linux since 2002 and in embedded Android since 2010. He has delivered hundreds of sessions to many well-known companies. You can see some of his work on the 'Inner Penguin' blog at www.2net.co.uk., Table of Contents, Starting OutLearning About ToolchainsAll About BootloadersPorting and Configuring the KernelBuilding a Root FilesystemSelecting a Build SystemCreating a Storage StrategyIntroducing Device DriversStarting up - the init ProgramLearning About Processes and ThreadsManaging MemoryDebugging with GDBProfiling and TracingReal-time Programming

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值