[Toybox] pmap notes.

Rob Landley rob at landley.net
Thu Aug 29 15:49:01 PDT 2013


I didn't initially post notes on a pmap cleanup because A) I'm
switching computers and my email is still screwed up (although ui=html
makes gmail's web interface barely tolerable), and because the cleanup
evolved into more or less a complete ground-up rewrite of the command.

But just for the record, here's the notes file I was assembling before
I decided to do that:

---

This is the first I've even heard of the pmap command, I always just
looked directly at the /proc/$PID/maps output. What do you need it
for?

Its main output seems like a sed command run against /proc/$PID/maps,
but you're parsing smaps for the -x mode. Do you _need_ the -x mode?

Let's see...

#if ULONG_MAX == 0xffffffff
 # define TAB "\t"
 # define WIDTH "8"
 # define DASHES ""
#else
 # define TAB "\t\t"
 # define WIDTH "16"
 # define DASHES "--------"
#endif

Um... no. We're not doing that.

I'm removing the underscore from struct _smaps. (We're not
implementing a C library and worrying about namespace pollution...) In
fact... we're reading a single file and printing it, why are we saving
values in a structure? What's the structure for, if we _do_ need to
cache data for the curent mapping couldn't we just use local
variables?

Functionally speaking, comparing this to the implementation in ubuntu,
it doesn't show the file association for the mapping, the flags are
different, and the spacing is off.

What a horrible command: the pmap man page doesn't say what the flags
_are_. It turns p in the fourth position into -, but the - in the 5th
position is... what? Just always a "-"? If you run it on a kernel
thread (even as root!), it produces weird truncated output but no
error...

Sigh. The spacing is actually the first thing that makes comparing the
output between the two implementations tricky. Let's see, how is that
calculated? Is it doing the "ls" thing of producing all the output
into a buffer, measuring the columns, and then outputting with padding
to the longest value? Hmmm, none of my processes have an allocation
big enough to force it to adjust. Ok, write a dumb little program to
malloc 2 gigs and memset it, and:

0000000000601000      4K rw---  /home/landley/toybox/toybox/a.out
00007f7501cd1000 1953128K rw---    [ anon ]
00007f757902b000   1784K r-x--  /lib/x86_64-linux-gnu/libc-2.17.so

Ok, no it's not. The spacing is hardwired 7 characters, breaking to
the right if it goes long.

 1377816541.0


More information about the Toybox mailing list