Article [#4311] profiling script "grab_maps_from_board.sh" cannot work in some cases

[#4311] profiling script "grab_maps_from_board.sh" cannot work in some cases

Submitted By: Yi Li

Open Date

2008-08-05 02:34:10     Close Date

2010-06-11 16:23:18

Priority:

Medium     Assignee:

Robin Getz

Status:

Closed     Fixed In Release:

N/A

Found In Release:

2008R1.5-RC3     Release:

08r1, trunk

Category:

N/A     Board:

N/A

Processor:

ALL     Silicon Revision:

Is this bug repeatable?:

Yes     Resolution:

Fixed

Uboot version or rev.:

    Toolchain version or rev.:

any

App binary format:

N/A     

Summary: profiling script "grab_maps_from_board.sh" cannot work in some cases

Details:

Sometimes the pid.list contains wrong information:

On the board:

root:/> ps

  PID  Uid        VSZ Stat Command

    1 root        104 S   /init

    2 root            SW< [kthreadd]

    3 root            SWN [ksoftirqd/0]

    4 root            SW< [events/0]

    5 root            SW< [khelper]

   45 root            SW< [kblockd/0]

   46 root            SW< [ata/0]

   47 root            SW< [ata_aux]

   50 root            SW< [khubd]

   69 root            SW  [pdflush]

   70 root            SW  [pdflush]

   71 root            SW< [kswapd0]

   72 root            SW< [aio/0]

   73 root            SW< [cifsoplockd]

   74 root            SW< [cifsdnotifyd]

  176 root            SW< [scsi_eh_0]

  184 root            SW< [mtdblockd]

  200 root            SW< [bfin-spi.0]

  203 root            SW< [bfin-spi.1]

  249 root         40 S   inetd

  251 root        580 S   -/bin/sh

  252 root        580 S   -/bin/sh

  255 root         32 S   /bin/watchdogd -f -s

  256 root        480 S   /sbin/syslogd -n

  257 root        480 S   /sbin/klogd -n

  271 root      13546 S   ./pictureflow -qws

  291 root         56 S   /bin/telnetd

  292 root        580 S   sh

  398 root        392 S < mp3play -q /mnt/test2.mp3

  399 root        484 R   ps

Run "./grab_maps_from_board.sh 192.168.0.9" on host:

# cat pid.list

init 1

inetd 249

sh 251

sh 252

watchdogd 255

syslogd 256

klogd 257

pictureflow 271

telnetd 291

sh 292

< 398

rshd 415

sh 416

ps 417

# rsh -l root 192.168.0.9  ps | grep -v "\[.*\]" | grep -v PID | awk '{print $1 " " $5 }' | awk -F "[/ ]" '{print $NF" " $1}'

init 1

inetd 249

sh 251

sh 252

watchdogd 255

syslogd 256

klogd 257

pictureflow 271

telnetd 291

sh 292

< 398

rshd 418

sh 419

ps 420

Follow-ups

--- Mike Frysinger                                           2008-08-05 03:44:17

prob best to filter it through `cut -b27-` first and assume `ps` gives a fixed

output format

i guess the question is, how robust exactly do we want this ...

--- Robin Getz                                               2008-08-05 15:21:56

I think this is fixed. (or - at least it worked on my board now

init 1

inetd 217

sh 250

sh 253

watchdogd 254

pictureflow 265

dhcpcd 276

mp3play 347

rshd 414

sh 415

ps 416

Let me know if there are any other issues.

-Robin

--- Yi Li                                                    2008-08-06 22:44:28

This issue has been fixed. But there is another problem with this script(will

not open another bug):

The "user.list" generated by grab_maps_from_board.sh contains zero

byte.

The script cannot handle the case of FLAT correctly.

root:/> cat /proc/maps

00279000-0027a000 rw-p 00000000 00:00 0

0027a000-0027b000 rw-p 00000000 00:00 0

00280000-002f8000 rwxp 00000000 00:00 0

00300000-00378000 rwxp 00000000 00:00 0

00380000-003f8000 rwxp 00000000 00:00 0

00400000-00431000 rw-p 00000000 00:00 0

00440000-00471000 rw-p 00000000 00:00 0

00480000-004f8000 rwxp 00000000 00:00 0

00500000-00578000 rwxp 00000000 00:00 0

00800000-008f5000 rw-p 00000000 00:00 0

00900000-009f5000 rw-p 00000000 00:00 0

00a00000-00a80000 rw-p 00000000 00:00 0

00a80000-00ab1000 rw-p 00000000 00:00 0

00ac0000-00af1000 rw-p 00000000 00:00 0

00b00000-00b31000 rw-p 00000000 00:00 0

00b40000-00b71000 rw-p 00000000 00:00 0

00b80000-00bb1000 rw-p 00000000 00:00 0

00bc0000-00bf1000 rw-p 00000000 00:00 0

00c00000-00c04000 rw-p 00000000 00:00 0

00c04000-00c05000 rw-p 00000000 00:00 0

00c08000-00c0b000 rw-p 00000000 00:00 0

00c0c000-00c10000 rw-p 00000000 00:00 0

00c20000-00c36000 rw-p 00000000 00:00 0

00c40000-00c79000 rw-p 00000000 00:00 0

00c80000-00cb9000 rw-p 00000000 00:00 0

00cc0000-00cf9000 rw-p 00000000 00:00 0

00d00000-00df5000 rw-p 00000000 00:00 0

00e00000-00e19000 rwxp 00000000 00:00 0

00e22000-00e23000 rw-p 00000000 00:00 0

02000000-0201a000 rw-p 00000000 00:00 0

02020000-02036000 rw-p 00000000 00:00 0

02040000-02049000 rwxp 00000000 00:00 0

02050000-02051000 rw-p 00000000 00:00 0

02051000-02052000 rw-p 00000000 00:00 0

02058000-02060000 rwxp 00000000 00:00 0

02062000-02063000 rw-p 00000000 00:00 0

02064000-02066000 rw-p 00000000 00:00 0

02066000-02068000 rw-p 00000000 00:00 0

0206a000-0206b000 rw-p 00000000 00:00 0

0206d000-0206e000 rw-p 00000000 00:00 0

02070000-02073000 rw-p 00000000 00:00 0

02075000-02076000 rw-p 00000000 00:00 0

02077000-02078000 rw-p 00000000 00:00 0

02078000-0207d000 rw-p 00000000 00:00 0

02080000-020f8000 rwxp 00000000 00:00 0

02100000-02116000 rw-p 00000000 00:00 0

02120000-02131000 rw-p 00000000 00:00 0

02140000-02141000 rw-p 00000000 00:00 0

02141000-02142000 rw-p 00000000 00:00 0

02142000-02143000 rw-p 00000000 00:00 0

02143000-02144000 rw-p 00000000 00:00 0

02144000-02145000 rw-p 00000000 00:00 0

02145000-02146000 rw-p 00000000 00:00 0

02146000-02147000 rw-p 00000000 00:00 0

02147000-02148000 rw-p 00000000 00:00 0

02148000-02149000 rw-p 00000000 00:00 0

02149000-0214a000 rw-p 00000000 00:00 0

0214a000-0214b000 rw-p 00000000 00:00 0

0214b000-0214c000 rw-p 00000000 00:00 0

0214c000-0214d000 rw-p 00000000 00:00 0

0214d000-0214e000 rw-p 00000000 00:00 0

0214e000-02150000 rw-p 00000000 00:00 0

02150000-0215d000 rw-p 00000000 00:00 0

02160000-0216c000 rwxp 00000000 00:00 0

02172000-02173000 rw-p 00000000 00:00 0

02173000-02174000 rw-p 00000000 00:00 0

02175000-02176000 rw-p 00000000 00:00 0

02179000-0217a000 rw-p 00019000 00:00 0

0217c000-0217d000 rw-p 00000000 00:00 0

0217e000-02180000 rw-p 00000000 00:00 0

02180000-021c1000 rw-p 00000000 00:00 0

02200000-022f5000 rw-p 00000000 00:00 0

02300000-023f5000 rw-p 00000000 00:00 0

02800000-02cbc000 rwxp 00000000 00:00 0

03983000-03984000 rw-p 00000000 00:00 0

03dd2000-03dd3000 rw-p 00000000 00:00 0

03e01000-03e60a00 rw-S 00000000 00:01 3441       /dev/fb0

root:/> cat /proc/maps | grep "x[ps] " | awk 'NF > 5'

root:/>

--- Robin Getz                                               2008-08-07 09:50:31

This is because flat files are mmaped into anonymous memory.

A simple:

Index: linux-2.6.x/fs/binfmt_flat.c

===================================================================

--- linux-2.6.x/fs/binfmt_flat.c        (revision 5076)

+++ linux-2.6.x/fs/binfmt_flat.c        (working copy)

@@ -605,7 +605,7 @@

                len = text_len + data_len + extra + MAX_SHARED_LIBS *

sizeof(unsigned long);

                len = PAGE_ALIGN(len);

                down_write(&current->mm->mmap_sem);

-               textpos = do_mmap(0, 0, len,

+               textpos = do_mmap(bprm->file, 0, len,

                                                PROT_READ | PROT_EXEC |

PROT_WRITE,

                                                MAP_PRIVATE, 0);

                up_write(&current->mm->mmap_sem);

will change things - but I need to do a little more testing to see if it causes

other problems....

-Robin

--- Mike Frysinger                                           2008-08-08 11:06:49

does this also fix [#2718] (/proc/self/exe) ?

otherwise, i like this change ... i think we should make it in trunk to see if

there's any fallout, and then post it upstream ... or do both simultaneously ...

--- Robin Getz                                               2008-08-08 13:37:12

I'm not sure - The link gets fixed, I can't say that it actually fixes things,

as I'm not sure what the expected behavior is

root:/> ls -l /proc/self/exe

lrwxrwxrwx    1 root     root            0 Aug  8 12:31 /proc/self/exe ->

/bin/busybox

root:/> /proc/self/exe ls

exe: applet not found

root:/> /bin/busybox ls

bin   etc   init  mnt   root  sys   usr

dev   home  lib   proc  sbin  tmp   var

root:/> ps | grep "bin/sh"

  316 root       544 S    -/bin/sh

  317 root       536 S    -/bin/sh

  333 root       432 S    grep bin/sh

root:/> ls -l /proc/316/exe

lrwxrwxrwx    1 root     root            0 Aug  8 12:31 /proc/316/exe ->

/bin/busybox

root:/> /proc/316/exe ls

exe: applet not found

?

--- Mike Frysinger                                           2008-08-08 14:05:38

the behavior you show is correct.  since argv[0] is shortened to

"exe", busybox tries to find an applet named "exe" and fails

which is why you see:

exe: applet not found

so i'd say let's start pushing this change

--- Yi Li                                                    2008-08-11 05:44:42

This fix seem too simple?

In the code following do_mmap():

result = bprm->file->f_op->read(bprm->file,

                                        (char *) textpos, text_len,

&fpos);

Howver, in mm/nommu.c: do_mmap_private()

if (vma->vm_file) {

                /* read the contents of a file into the copy */

                mm_segment_t old_fs;

                loff_t fpos;

                fpos = vma->vm_pgoff;

                fpos <<= PAGE_SHIFT;

                old_fs = get_fs();

                set_fs(KERNEL_DS);

                ret = vma->vm_file->f_op->read(vma->vm_file, base,

len, &fpos);

                set_fs(old_fs);

                if (ret < 0)

                        goto error_free;

                /* clear the last little bit */

                if (ret < len)

                        memset(base + ret, 0, len - ret);

        } else {

[snip]

So the file is actually read twice?

--- Robin Getz                                               2010-06-11 16:20:25

I think this has all been resolved,

cat /proc/maps | grep "x[ps] " | awk 'NF > 5'

028c0000-028c3000 r-xs 00000000 00:01 169        /bin/init

028c4000-028c6000 r-xs 00000000 00:01 239        /lib/libcrypt.so.0

028c8000-028cd000 r-xs 00000000 00:01 247        /lib/ld-uClibc.so.0

028d0000-028de000 r-xs 00000000 00:01 240        /lib/libgcc_s.so.1

02940000-02977000 r-xs 00000000 00:01 246        /lib/libc.so.0

02980000-029cd000 r-xs 00000000 00:01 208        /bin/busybox

02a3c000-02a3e000 r-xs 00000000 00:01 70         /bin/watchdogd

02a44000-02a47000 r-xs 00000000 00:01 154        /bin/inetd

02b68000-02b6d000 r-xs 00000000 00:01 119        /bin/telnetd

02b70000-02b71000 r-xs 00000000 00:01 236        /lib/libutil.so.0

02c90000-02c99000 r-xs 00000000 00:01 143        /bin/dhcpcd

02c90000-02c99000 r-xs 00000000 00:01 143        /bin/dhcpcd

so, marking closed.

    Files

    Changes

    Commits

    Dependencies

    Duplicates

    Associations

    Tags

File Name     File Type     File Size     Posted By

No Files Were Found

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.