When debugging the upper-level program, often encountered error is a segment error, when there is a segment error, the system will often only give a segmention error, and in no more information (default does not produce core dump), in this case, you can modify the kernel boot parameters to enable debugging mode, Let the user state in the event of a segment error, print out more information, help to locate the error.
Analysis Process:
The following fields are usually printed when a kernel-state segment error occurs, starting with a kernel-state segment error:
Unable to handle kernel paging request at virtual address 56000050
Given that the mainstream architecture is arm, we can locate it in the following way, under the kernel directory arch/arm/directory:
Locate the file that contains the code:
1: staticvoid
2: __do_kernel_fault (structlongint FSR,
3: struct pt_regs *regs)
4: {
5: / *
6: * is we prepared to handle this kernel fault?
7: * /
8: if (Fixup_exception (regs))
9: return;
Ten:
One : / *
: * No Handler, we'll have the terminate things with extreme prejudice.
* /
: bust_spinlocks (1);
: PRINTK (kern_alert
: "Unable to handle kernel%s at virtual address%08lx\n",
: "NULL pointer dereference" :
: "Paging Request", addr);
:
: show_pte (mm, addr);
: die ("Oops", Regs, FSR);
: bust_spinlocks (0);
At : do_exit (SIGKILL);
: }
This function is called here:
1: voidlongintstruct pt_regs *regs)
2: {
3: struct task_struct *tsk = current;
4: struct mm_struct *mm = tsk->active_mm;
5:
6: / *
7: * If We is in kernel mode at this point, we
8: * There is no context to handle the fault with.
9: * /
: if (User_mode (regs))
One : __do_user_fault (tsk, addr, FSR, SIGSEGV, Segv_maperr, regs);
: Else
: __do_kernel_fault (mm, addr, FSR, regs);
: }
As can be seen from the above, if the user state access to the illegal zone, will call the __do_user_fault function, in the kernel state, will call the __do_kernel_fault function.
We enter __do_user_fault to view:
1: staticvoid
2: __do_user_fault (structlong addr,
3: int int int Code,
4: struct pt_regs *regs)
5: {
6: struct siginfo si;
7:
8: #ifdef Config_debug_user
9: if (User_debug & UDBG_SEGV) {
Ten: "%s:unhandled page fault (%d) at 0X%08LX, code 0x%03x\n",
One : Tsk->comm, Sig, Addr, FSR);
: show_pte (tsk->mm, addr);
: show_regs (regs);
: }
: #endif
A : .....
:
: }
As can be seen from the above, in order to print more debugging information in the user state, need
1. Kernel Configuration Config_debug_user macros
#define UDBG_UNDEFINED (1 << 0)//Generate undefined instruction information
#define UDBG_SYSCALL (1 << 1)//Generate illegal system calls
#define UDBG_BADABORT (1 << 2)
#define UDBG_SEGV (1 << 3)//Generate segment error message
#define UDBG_BUS (1 << 4)
1:
2: #ifdef Config_debug_user
3: int user_debug;
4:
5: staticint __init user_debug_setup (char *str)
6: {
7: get_option (&str, &user_debug);
8: return 1;
9: }
Ten: __setup ("user_debug=", User_debug_setup);
One : #endif
Analysis here, we know, can pass to the kernel through the uboot boot parameter Bootargs, set user_debug = 0xFF, open all user-state debugging information
Since then, when the user state program is executed, when a segment error occurs, a lot of information is displayed, where the useful value is the PC value.
We can analyze this PC value for the specific sentence assembly instruction by disassembling the application:
Arm-linux-objdump–d test_debug > Test_debug.dis, search for PC values in Test_debug.dis: 84AC to compare register information when an error occurs.
Technorati Tags: debugging
Print more user-state segment error messages