Debugging With Strace

May 25th, 2005 by markmc

I just check in a short doc explaining some tricks to use when debugging Vino.

I got a bit side tracked explaining how you can figure out what messages are being sent back and forth to the X server, just by looking at the read()s and write()s in the strace. A snippet:

[markmc@blaa ~]$ grep -rn X_QueryExtension /usr/include/X11/Xproto.h
2091:#define X_QueryExtension               98

  That's 0x62 in hex. So, we're looking for a write to the X
connection (file descriptor 3) with 0x62 as the first byte. What do ya
know:

1117012824.950683 writev(3, [{"\x62\x01\x04\x00\x06\x00\x01\x00", 8}, {"DAMAGE", 6}, {"\x00\x00", 2}], 3) = 16
1117012824.950939 read(3, "\x01\x00\x52\x00\x00\x00\x00\x00\x01\x9d\x75\xba\x00\x00"..., 32) = 32

  It's pretty clear that its QueryExtension for DAMAGE. Now, lets
figure out the event base from the reply. The format for the reply is:

typedef struct {
    BYTE type;  /* X_Reply */
    BYTE pad1;
    CARD16 sequenceNumber B16;
    CARD32 length B32; /* 0 */
    BOOL  present;
    CARD8 major_opcode;
    CARD8 first_event;
    ...
} xQueryExtensionReply;

   first_event is 11 bytes in. Looking at the read, that's 0x75. The
value of XDamageNotify is zero, so we can be 100% sure that all those
events after our NoExpose events are XDamageNotify events.

Some people might find it interesting. Others will think I’m weird and tell me to use something like xscope.

Random Hacker Tool #753

May 24th, 2005 by markmc

For all those of you swimming in bug mail, I give you the super spiffy “Delete Resolved Bugs” plugin for Evolution. Woo.

I can’t say its saved my life or anything, but its made a difference …

Design By Scribble

May 13th, 2005 by markmc

Yesterday, I finally got around to hacking up a dialog in Sabayon where you can assign profiles to users. Code-wise, I knew it was pretty trivial, but for once I decided to spend some time thinking about the UI design rather than hoping a real designer would come along and rescue me later.

So, I scribbled down a rough design, humed and hawed for a while and got hacking. I’m not totally depressed with the end result, so that’s something …

Stack Guard Page

May 11th, 2005 by markmc

The most interesting little tidbit I learnt from the memory usage
debugging yesterday was
about the “stack guard page”. Look at this bit in the strace:

mmap2(NULL, 10489856, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7219000
mprotect(0xb7219000, 4096, PROT_NONE)   = 0
clone(child_stack=0xb7c194c4, flags=CLONE_VM|...) = 2282

What’s going on here is that libc is mapping an area for the thread’s
stack, just before spawning thread. The interesting bit is that, using
mprotect(), it also changes the permissions on the first page
(the page at the top of the stack) such that any instruction which
attempts to write to the page will cause a segmentation fault.

That’s your stack guard page; it means that your infinitely recursing
function won’t go off an scribble over its neighbouring thread’s stack,
it’ll just segfault like a good little thread.

(In true pthreads tradition, you can even configure the size of
this guard area – see the pthread_attr_setguardsize() manpage)

Memory Usage Debugging

May 10th, 2005 by markmc

There’s been a lot of talk about reducing memory usage in GNOME, so
some people may be interested in the little
adventure
I had this morning tracking down a mysterious 10M that
appeared in gnome-panel’s memory map in FC4.

Update: I better clarify that to avoid misunderstandings … this is
10M of unused virtual memory, not physical memory. The kernel would
only have ever allocated a handful of physical pages in this space.
This does not mean that GNOME now uses 10M less of your RAM.

Architecture Astronauts

May 9th, 2005 by markmc

I’d read some of Joel’s articles
before, not never really got around to reading a lot of them. Maybe its
because I hate reading long articles on a computer; maybe its because I
only became aware of his stuff well after he was at his most prolific.

Anyway, I’m thoroughly enjoying reading the
book
at the moment. Catherine gave me her typical “you’re such a freak” look
last night as I chuckled to myself over this description of Architecture
Astronauts
:

When you go too far up, abstraction-wise, you run out of oxygen. Sometimes smart thinkers just don’t know when to stop, and they create these absurd, all-encompassing, high-level pictures of the universe that are all good and fine, but don’t actually mean anything at all.

Session Migration With GDM

April 26th, 2005 by markmc

Last year Caolan
and I demoed hotdesking with GDM and VNC. Owen later pointed out that VNC
probably wasn’t the way to go once the rendering
improvements
they’re working come on line.

So, last week I picked up a patch I’d hacked up before Christmas,
finished it off and committed it to GDM. The idea is to do the same
thing as the VNC patch, but this time using a X proxy (like Xnest)
server on the terminal server instead of a VNC server.

Specifically, though, the features added to GDM are:

  • You can now configure GDM to run XDMCP sessions on a local X
    proxy server. This may be useful on its own for performance reasons;
    in theory, at least, an X proxy server should be able to limit the
    number of roundtrips it makes to the remote X server since if all you
    want to do is query server state, then that state is local. I’ve no
    idea yet how well Xnest and others do on this in practice, though.
  • If the proxy server supports disconnecting from its parent
    display and re-connecting later, you can configure GDM such that you
    can disconnect from your session and reconnect later simply by logging
    back in. The only proxy server’s that I know of which support this is
    the DMX X server and NoMachine NX’s nxagent. Its
    certainly possible to do this with any proxy though; I had it half
    done for Xnest before realizing DMX had good enough support to get the
    GDM patch done.

I’ve played around a little today with NoMachine’s proxy. You can try
it out with GDM HEAD up by:

  1. Install NoMachine’s server package
  2. Set xdmcp/EnableProxy=true in gdm.conf
  3. Download these scripts (run-nxagent.sh
    and reconnect-nxagent.sh)
    and stick them in /tmp
  4. Set xdmcp/ProxyXServer to
    ProxyXServer=/tmp/run-nxagent.sh -audit 0 -name NX -geometry
    768x576
    and xdmcp/ProxyReconnect to
    /tmp/reconnect-nxagent.sh
  5. Re-start GDM
  6. From another machine run X -query $server and login
    through the login screen
  7. Run /tmp/reconnect-nxagent.sh --to :20 on the server to
    disconnect your remote X server from the session
  8. Run X -query $server again on the server, login and you
    should be immediately re-directed to your original session

Evolution Mail Account LDAP Backend For GConf

April 14th, 2005 by markmc

(Jaysus, thats a very long name for a few hundred lines of
code)

I’ve just finished hacking on what was a really interesting little
project. Basically, its a GConf backend which uses information in
the user’s LDAP entries to generate the mail account configuration for
Evolution. The idea is that if you’ve a large number of users, all you
have to do is stick each user’s email address, incoming mail server and
outgoing mail server in her LDAP entry and Evolution should just
magically work.

I’m really happy with how well this thing turned out. I mean, it
actually works, it didn’t take much code, there wasn’t anything
lurking in GConf or Evo waiting to stab me in the back … and, most
of all, it should actually be very useful.

The code is in evolution-gconf-ldap-backend
in GNOME CVS and more details are in the README.

What’s more, Dave Malcolm has also written some cool
scripts
to solve the same problem, but without LDAP.

Rugby Weekend

February 28th, 2005 by markmc

Another big Six
Nations
rugby weekend over that saw Scotland beat Italy in the
dullest international game in a while, Wales beating France in a
breathtaking match in Paris and Ireland beating world champions
England in a tense, down-to-the-wire encounter in Dublin.

Its all looking like it’ll end with a grand slam showdown between
Ireland and Wales in Cardiff. Who would have thought it?

The most bizarre example of how professionalism has changed Irish
rugby is that Brian O’Driscoll, Ireland’s star centre, having strained
his hamstring was sent to this whole body
cryotherapy unit
where you get put in a freezer at below -120°C
(-184°F) for a few minutes so that you can train at four times the
inensity for the next few hours. Three weeks after an injury that
would have put players out for months and he’s back on the pitch
leading the team and scoring tries.

A Certain Rocking Vuntz

February 25th, 2005 by markmc

So, I just plowed through a few hundred emails in my gnome-panel bugzilla.gnome.org folder. In one
sense it was incredibly boring, because I don’t think I actually
interacted with a single bug report, but in another sense its was just
incredibly awesome. The folder appears to be just full of bugs which
Vincent Untz has already
closed. Rocking!

I didn’t know Vincent had a blog, interesting. I’ll need to
polish my French a bit to understand it, though. About all I could
understand was "J'adore vim". I guess its a good thing he
uses vim, really. If he used emacs he’d put us all to even more
shame fixing even more bugs.