[git commit] init: add a segv debugging aid, disabled by default

walter harms wharms at bfs.de
Mon Jan 30 13:36:19 UTC 2012


hi,
glibc has a backtrace() function. I do not know how portable that is.

there is also getcontext() to make that more portable:
 http://www.delorie.com/gnu/docs/glibc/libc_465.html

Personally i would make that an example how to debug it since debugging
this is not a standard case.

re,
 wh


Am 30.01.2012 13:11, schrieb Abdoulaye Walsimou Gaye:
> On 01/30/2012 12:15 PM, Denys Vlasenko wrote:
>> commit:
>> http://git.busybox.net/busybox/commit/?id=da2b2da6a708edffcc3b405ab5fd7f3f11af5d33
>>
>> branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master
>>
>> Signed-off-by: Denys Vlasenko<vda.linux at googlemail.com>
>> ---
>>   init/init.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
>>   1 files changed, 51 insertions(+), 0 deletions(-)
>>
>> diff --git a/init/init.c b/init/init.c
>> index c540faa..7248946 100644
>> --- a/init/init.c
>> +++ b/init/init.c
>> @@ -108,6 +108,8 @@
>>   //config:      Note that on Linux, init attempts to detect serial
>> terminal and
>>   //config:      sets TERM to "vt102" if one is found.
>>
>> +#define DEBUG_SEGV_HANDLER 0
>> +
>>   #include "libbb.h"
>>   #include<syslog.h>
>>   #include<paths.h>
>> @@ -118,6 +120,15 @@
>>   #endif
>>   #include "reboot.h" /* reboot() constants */
>>
>> +#if DEBUG_SEGV_HANDLER
>> +# undef _GNU_SOURCE
>> +# define _GNU_SOURCE 1
>> +# undef __USE_GNU
>> +# define __USE_GNU 1
>> +# include<execinfo.h>
>> +# include<sys/ucontext.h>
>> +#endif
>> +
>>   /* Used only for sanitizing purposes in set_sane_term() below. On
>> systems where
>>    * the baud rate is stored in a separate field, we can safely
>> disable them. */
>>   #ifndef CBAUD
>> @@ -957,6 +968,33 @@ static int check_delayed_sigs(void)
>>       }
>>   }
>>
>> +#if DEBUG_SEGV_HANDLER
>> +static
>> +void handle_sigsegv(int sig, siginfo_t *info, void *ucontext)
>> +{
>> +    long ip;
>> +    ucontext_t *uc;
>> +
>> +    uc = ucontext;
>> +    ip = uc->uc_mcontext.gregs[REG_EIP];
>>
>>    
> [...]
> 
> Hi Denys,
> Are you sure that this part of code is portable?
> Last time I looked uc->uc_mcontext data structure was not.
> I am working with an ARM gcc-.4.4.5 toolchain currently for instance,
> here is how uc_mcontext is defined:
> 
> struct sigcontext {
>     unsigned long trap_no;
>     unsigned long error_code;
>     unsigned long oldmask;
>     unsigned long arm_r0;
>     unsigned long arm_r1;
>     unsigned long arm_r2;
>     unsigned long arm_r3;
>     unsigned long arm_r4;
>     unsigned long arm_r5;
>     unsigned long arm_r6;
>     unsigned long arm_r7;
>     unsigned long arm_r8;
>     unsigned long arm_r9;
>     unsigned long arm_r10;
>     unsigned long arm_fp;
>     unsigned long arm_ip;
>     unsigned long arm_sp;
>     unsigned long arm_lr;
>     unsigned long arm_pc;
>     unsigned long arm_cpsr;
>     unsigned long fault_address;
> };
> 
> typedef struct sigcontext mcontext_t;
> 
> /* Userlevel context.  */
> typedef struct ucontext
>   {
>     unsigned long uc_flags;
>     struct ucontext *uc_link;
>     stack_t uc_stack;
>     mcontext_t uc_mcontext;
>     __sigset_t uc_sigmask;
>     unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
>   } ucontext_t;
> 
> as you can see, there is no 'gregs' field.
> I think this part of your code is specific to x86.
> 
> Best regards,
> AWG
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
> 
> 


More information about the busybox mailing list