Skip to contentSkip to conversation

Why dump_stack results different so much?

DISCUSSION Xin Zhao 2 participants 6 messages Jul 29, 2005 – Jul 30, 2005

lore
Share & tools
lore

Xin Zhao

author
#0 lore raw

I tried to use dump_stack to dump the calling trace in the kernel. What I did is adding a dump_stack() call in the sys_open function.

Below is the dump out result:

Jul 28 17:33:31 normal kernel:  [<c0151601>] sys_open+0xa6/0xb7
Jul 28 17:33:31 normal kernel:  [<c0108e2c>] syscall_call+0x7/0xb

However, if I insert a new kernel module which does nothing but pointing the orignal sys_open to our_sys_open(), and in our_system_open(), I simply do return sys_open();

I supprisely noticed that the dump_stack results are quite different! Why did I get the calling traces below our_ssy_open() and above syscall_call()? Any thought on this? Many thanks!

Jul 28 17:33:42 normal kernel:  [<c0151601>] sys_open+0xa6/0xb7
Jul 28 17:33:42 normal kernel:  [<d080f02c>] our_sys_open+0x2c/0x33 [trace]
Jul 28 17:33:42 normal kernel:  [<c0114984>] __wake_up+0x41/0x81
Jul 28 17:33:42 normal kernel:  [<c02c5e44>] sbf_read+0x5a/0x6f
Jul 28 17:33:42 normal kernel:  [<c01c4e12>] journal_stop+0x159/0x279
Jul 28 17:33:42 normal kernel:  [<c01b7aff>] ext3_mark_iloc_dirty+0x25/0x2f
Jul 28 17:33:42 normal kernel:  [<c02c5e44>] sbf_read+0x5a/0x6f
Jul 28 17:33:42 normal kernel:  [<c01b7bef>] ext3_mark_inode_dirty+0x3d/0x44
Jul 28 17:33:42 normal kernel:  [<c02c5e44>] sbf_read+0x5a/0x6f
Jul 28 17:33:42 normal kernel:  [<c01c583a>] __journal_file_buffer+0xbb/0x282
Jul 28 17:33:42 normal kernel:  [<c01546ed>] bh_lru_install+0xc3/0xdf
Jul 28 17:33:42 normal kernel:  [<c01c4169>] do_get_write_access+0x36f/0x5ea
Jul 28 17:33:42 normal kernel:  [<c01c583a>] __journal_file_buffer+0xbb/0x282
Jul 28 17:33:42 normal kernel:  [<c01c4a39>] journal_dirty_metadata+0xf4/0x16d
Jul 28 17:33:42 normal kernel:  [<c0114984>] __wake_up+0x41/0x81
Jul 28 17:33:42 normal kernel:  [<c01c4e12>] journal_stop+0x159/0x279
Jul 28 17:33:42 normal kernel:  [<c01b7aff>] ext3_mark_iloc_dirty+0x25/0x2f
Jul 28 17:33:42 normal kernel:  [<c01b7bef>] ext3_mark_inode_dirty+0x3d/0x44
Jul 28 17:33:42 normal kernel:  [<c01bc111>] __ext3_journal_stop+0x1e/0x44
Jul 28 17:33:42 normal kernel:  [<c01b7c5c>] ext3_dirty_inode+0x66/0x7b
Jul 28 17:33:42 normal kernel:  [<c01736fc>] __mark_inode_dirty+0xec/0x1ce
Jul 28 17:33:42 normal kernel:  [<c011cbd4>] current_fs_time+0x4d/0x5b
Jul 28 17:33:42 normal kernel:  [<c0107606>] __switch_to+0x2a/0x365
Jul 28 17:33:42 normal kernel:  [<c0107606>] __switch_to+0x2a/0x365
Jul 28 17:33:42 normal kernel:  [<c0132c3d>] find_get_page+0x30/0x6a
Jul 28 17:33:42 normal kernel:  [<c015f35b>] do_lookup+0x24/0x89
Jul 28 17:33:42 normal kernel:  [<c01686fc>] dput+0x95/0x252
Jul 28 17:33:42 normal kernel:  [<c015ff9d>] link_path_walk+0xbdd/0xe86
Jul 28 17:33:42 normal kernel:  [<c0121778>] free_uid+0x1c/0x6d
Jul 28 17:33:42 normal kernel:  [<c01e63de>] copy_to_user+0x3c/0x4a
Jul 28 17:33:42 normal kernel:  [<c015b519>] cp_new_stat64+0xf5/0x105
Jul 28 17:33:42 normal kernel:  [<c015b55a>] sys_stat64+0x31/0x36
Jul 28 17:33:42 normal kernel:  [<c0108e2c>] syscall_call+0x7/0xb
#1 lore raw
Quoted 3 lines · Xin Zhao

I supprisely noticed that the dump_stack results are quite different! Why did I get the calling traces below our_ssy_open() and above syscall_call()? Any thought on this? Many thanks!

This might depend on compiling with frame pointers, or not. I recall that at one point, the kernel did a basic scan of addresses that looked like likely candidates to have been pointers, and printed those.

Frame pointers are hailed as improving backtraces. They are in the 'kernel hacking' section of the kernel configuration.

Sorry that I can't be more precise, but try turning on frame pointers.

Good luck!

Signature · 2 lines
http://www.PowerDNS.com      Open source, database driven DNS Software 
http://netherlabs.nl              Open and Closed source services
author
#2 lore raw

Thanks for your reply.

Below is the code that print the kernel calling trace:

/**********************************************************************************/ void show_trace(struct task_struct *task, unsigned long * stack)

{
	unsigned long ebp;

	if (!task)
		task = current;

	if (task == current) {
		/* Grab ebp right from our regs */
		asm ("movl %%ebp, %0" : "=r" (ebp) : );
	} else {
		/* ebp is the last reg pushed by switch_to */
		ebp = *(unsigned long *) task->thread.esp;
	}

	while (1) {
		struct thread_info *context;
		context = (struct thread_info *)
			((unsigned long)stack & (~(THREAD_SIZE - 1)));
		ebp = print_context_stack(context, stack, ebp);
		stack = (unsigned long*)context->previous_esp;
		if (!stack)
			break;
		printk(" =======================\n");
	}
}

/**********************************************************************************/

Quoted 1 line

From this code, I can see that the show_trace does not scan and guess

the pointers. Instead, it use "previous_esp" to extract the esp and thus the returning eip. Am I right?

Cheers,
xin

Quoted 20 lines · bert hubert
Quoted 3 lines · Xin Zhao

I supprisely noticed that the dump_stack results are quite different! Why did I get the calling traces below our_ssy_open() and above syscall_call()? Any thought on this? Many thanks!

This might depend on compiling with frame pointers, or not. I recall that at one point, the kernel did a basic scan of addresses that looked like likely candidates to have been pointers, and printed those.

Frame pointers are hailed as improving backtraces. They are in the 'kernel hacking' section of the kernel configuration.

Sorry that I can't be more precise, but try turning on frame pointers.

Good luck!

--
http://www.PowerDNS.com Open source, database driven DNS Software
http://netherlabs.nl Open and Closed source services

#3 lore raw
Quoted 3 lines · Xin Zhao

Thanks for your reply.

Below is the code that print the kernel calling trace:

Can I suggest just turning on frame pointers like I suggested?

If you say Y here the resulting kernel image will be slightly larger and slower, but it will give very useful debugging information. If you don't debug the kernel, you can say N, but we may not be able to solve problems without frame pointers.

Good luck!

Signature · 2 lines
http://www.PowerDNS.com      Open source, database driven DNS Software 
http://netherlabs.nl              Open and Closed source services
author
#4 lore raw

Thanks. I will try. The only problem I have right now is I am using Xenolinux instead of standard Linux kernel, I cannot see the option to enable the frame pointer. But I will figure out how to enable that.

Again, thank you for your help!

Xin

Quoted 18 lines · bert hubert
Quoted 3 lines · Xin Zhao

Thanks for your reply.

Below is the code that print the kernel calling trace:

Can I suggest just turning on frame pointers like I suggested?

If you say Y here the resulting kernel image will be slightly larger and slower, but it will give very useful debugging information. If you don't debug the kernel, you can say N, but we may not be able to solve problems without frame pointers.

Good luck!

--
http://www.PowerDNS.com Open source, database driven DNS Software
http://netherlabs.nl Open and Closed source services

#5 lore raw
Quoted 3 lines · Xin Zhao

Thanks. I will try. The only problem I have right now is I am using Xenolinux instead of standard Linux kernel, I cannot see the option to enable the frame pointer. But I will figure out how to enable that.

If you ever report something odd again, remember to inform the readers here of any odd patches you are running with; they might be the *cause* of what you are seeing!

Signature · 2 lines
http://www.PowerDNS.com      Open source, database driven DNS Software 
http://netherlabs.nl              Open and Closed source services