Math problems and marriage

January 12, 2013 § 1 Comment

So, at tea this afternoon:

Me: Hey, Vivienne, here’s a cool math problem:

Vivienne: [skeptical expression]

Me: Suppose I give you an envelope with $20 in it, and I have another
envelope with either half that much or twice that much in it. I offer
to trade the envelope you’ve got for the one I have. Do you take the

Vivienne: No. $20 is enough.

After twelve years of marriage, sometimes I can’t tell whether she
loves me, or whether she hates me but we get along well.

Happy Birthday, Ben!

January 5, 2013 § Leave a comment

My dear friend Ben Collins-Sussman has just turned 40! Please join me in congratulating him, and in associating his name with that web page. Ahem.

Support for debugging SpiderMonkey with GDB now landed

January 2, 2013 § 1 Comment

The main source tree for Firefox, Mozilla Central, now includes some code that should make debugging SpiderMonkey with GDB on Linux much more pleasant and productive.

GDB understands C++ types and values, but naturally it has no idea what the debuggee intends them to represent. As a result, GDB’s attempts to display those values can sometimes be worse than printing nothing at all. For example, here’s how a stock GDB displays a stack frame for a call to js::baseops::SetPropertyHelper:

(gdb) frame
#0 js::baseops::SetPropertyHelper (cx=0xc648b0, obj={<js::HandleBase> = {}, ptr = 0x7fffffffc960}, receiver={<js::HandleBase> = {}, ptr = 0x7fffffffc960}, id={<js::HandleBase> = {}, ptr = 0x7fffffffc1e0}, defineHow=4, vp={<js::MutableHandleBase> = {<js::MutableValueOperations<JS::MutableHandle >> = {<js::ValueOperations<JS::MutableHandle >> = {}, }, }, ptr = 0x7fffffffc1f0}, strict=0) at /home/jimb/moz/dbg/js/src/jsobj.cpp:3593

There exist people who can pick through that, but for me it’s just a pile of hexadecimal noise. And yet, if you persevere, what those arguments represent is quite simple: in this case, obj and receiver are both the JavaScript global object; id is the identifier "x"; and vp refers to the JavaScript string value "foo". This SetPropertyHelper call is simply storing "foo" as the value of the global variable x. But it sure is hard to tell—and that’s an annoyance for SpiderMonkey developers.

As of early December, Mozilla Central includes Python scripts for GDB that define custom printers for SpiderMonkey types, so that when GDB comes across a SpiderMonkey type like MutableValueHandle, it can print it in a meaningful way. With these changes, GDB displays the stack frame shown above like this:

(gdb) frame
#0 js::baseops::SetPropertyHelper (cx=0xc648b0, obj=(JSObject * const) 0x7ffff151f060 [object global] delegate, receiver=(JSObject * const) 0x7ffff151f060 [object global] delegate, id=$jsid("x"), defineHow=4, vp=$jsval("foo"), strict=0) at /home/jimb/moz/dbg/js/src/jsobj.cpp:3593

Here it’s much easier to see what’s going on. Objects print with their class, like “global” or “Object”; strings print as strings; jsval values print as appropriate for their tags; and so on. (The line breaks could still be improved, but that’s GDB for you.)

Naturally, the pretty-printers work with any command in GDB that displays values: print, backtrace, display, and so on. Each type requires custom Python code to decode it; at present we have pretty-printers for JSObject, JSString, jsval, the various Rooted and Handle types, and things derived from those. The list will grow.

GDB picks up the SpiderMonkey support scripts automatically when you’re debugging the JavaScript shell, as directed by the file that the build system places in the same directory as the js executable. We haven’t yet made the support scripts load automatically when debugging Firefox, as that’s a much larger audience of developers, and we’d like a chance to shake out bugs before foisting it on everyone.

Some versions of GDB are patched to trust only auto-load files found in directories you’ve whitelisted; if this is the case for you, GDB will complain, and you’ll need to add a command like the following to your ~/.gdbinit file:

# Tell GDB to trust auto-load files found under ~/moz.
add-auto-load-safe-path ~/moz

If you need to see a value in its plain C++ form, with no pretty-printing applied, you can add the /r format modifier to the print command:

(gdb) print vp
$1 = $jsval("foo")
(gdb) print/r vp
$2 = {
  <js::MutableHandleBase> = {
    <js::MutableValueOperations<JS::MutableHandle >> = {
      <js::ValueOperations<JS::MutableHandle >> = {}, }, },
  members of JS::MutableHandle:
  ptr = 0x7fffffffc1f0

If you run into troubles with a pretty-printer, please file a bug in Bugzilla, under the “Core” product, for the “JavaScript Engine” component. (The pretty-printers have their own unit and regression tests; we do want them to be reliable.) In the mean time, you can disable the pretty-printers with the disable pretty-printer command:

(gdb) disable pretty-printer .* SpiderMonkey
12 printers disabled
128 of 140 printers enabled

For more details, see the GDB support directory’s README file.

Linear algebra textbooks

December 31, 2011 § 3 Comments

On Twitter, I asked:

Sincere question: do any of you have a linear algebra introductory text that you really liked?

(Man, this blog is just going to rocket to the top of the charts, I can tell.)

Here’s what people mentioned:

Prices are from Powell’s Books, for comparison. Powell’s prices aren’t the lowest, but I consider the physical bookstore (and especially the technical bookstore, oh my goodness) a substantial side benefit, so I try to buy from them anyway. But, wow, tutelage on the fundamental truths of the universe is not cheap. However much I love bookstores, I think I might like open-sourced textbooks even more…

Anime series we watch with our daughters

December 18, 2011 § Leave a comment

On Twitter, I wrote:

Between ARIA, Saiunkoku, and Akage no Anne, we may’ve watched enough anime with our girls about women who work hard and achieve their goals.

Some folks were interested, so here are some details on those series.
First, some things you should know about our tastes in anime:

  • They run strongly towards the gentle and slow-paced, because that’s what our girls (9 and 6) like. If your kids think Jurassic Park is great fun, this isn’t the list for you. If we ever watched something even as severe as, say, Star Wars, they would be crying so loudly I wouldn’t be able to hear Luke tell Obi-wan, “I want to come with you to Alderaan.” (Which is a problem… how?)
  • Every single one of these series extolls the virtues of hard work and an honest, forthright character. The truth is, I’m not sure I could explain to the next generation why being an anarchist punk isn’t the better choice. I sure hope good parenting doesn’t entail making the family a miniature of the world outside.
  • It’s surprisingly easy to find anime that passes the Bechdel Test, so why settle for less? (I hear a lot about how constraining Japanese society is for women, and I believe it, but I also come across a lot that doesn’t fit neatly into that picture.)

So, the anime:

  • Aria
    A young woman leaves Earth to be an apprentice gondolier in a rebuilt Venice on a terraformed Mars. But it’s barely sci-fi at all; it’s entirely about the characters, about the nature of kindness, friendship, study, and community. The sense of place in Aria is so strong, I wanted to move to Neo-Venezia myself. The plots are idiosyncratic: nobody else has ever had a character undertake a punishment campaign against her own left hand.

    If you have a limited tolerance for sweetness, Aria will probably give you diabetes. “Cool” is big in American culture, and Aria has nothing to do with detachment and independence. But from 2004 to 2009, when I was avidly (compulsively) following the cruel and banal mendacity that is American politics, watching Aria on Fridays was like a balm for my soul. There’s something there. Aria makes you wonder why arguments and conflict are such essential ingredients in almost all drama when you can actually have great stories without them.

    There’s a bit of Fan service in one early episode, which usually bugs me (it’s condescending to the viewers, and also strikes me as disrespectful to the characters—whatever that means), but please forgive it. It’s nothing my girls even blinked at.

  • Saiunkoku
    Shuurei, a young woman in a poor but noble family, is roped into being the king’s consort in an attempt to awaken his interest in ruling. He falls in love with her, but she aspires to become a government official, even though the civil service exam is not open to women. Predictably, the king gets the rules changed, and Shuurei aces the exam.

    A good bit of the series deals with Shuurei’s troubles gaining the respect of her colleagues despite her manifest competence, and the reactions of the male-dominated court culture to the introduction of a woman. Her supporters hesitate to intervene on her behalf, knowing that her detractors are eager to attribute her success to favoritism. But she perseveres and triumphs.

    Visually, Saiunkoku is weak; this is classic cheap Japanimation. The fun is all in the plot, which is pretty complicated. It definitely goes over our 6-year-old’s head, and our 9-year-old misses a lot too, but there’s enough for the kids to latch on to that they seem to enjoy it as well.

  • Akage no Anne
    This is an anime adaptation of Anne of Green Gables, a novel set in 1878 Canada about a young girl who is adopted by an elderly couple. She goes to school; makes friends; climbs a roof on a dare and falls off; accidentally gets her best friend drunk on currant wine; and so on. She is an accomplished student, gains admission to Queen’s Academy, and wins a scholarship to college.

    The story often sympathetically articulates Anne’s adoptive parents’ feelings; I was glad to have that angle set out to our girls.

    Isao Takahata and Hayao Miyazaki worked together on this anime.

A favorite quote

January 6, 2011 § Leave a comment

The future masters of technology will have to be light-hearted and intelligent. The machine easily masters the grim and the dumb.

—Marshall McLuhan, 1969

I love this quote. It roughly fits what I’ve seen. But while it seems clear that being ‘dumb’ probably dooms you to being mastered by the first anything (person, cause, addiction, …) you encounter, why would being light-hearted have anything to do with it?

Emacs hacks for Mozilla hackers

January 5, 2011 § 3 Comments

If you use Emacs to work on Mozilla code, you might find something you like in my mozilla-elisp repository. It currently includes:

  • mozilla-c-style.el, a package which defines a C/C++ indentation style named “Mozilla”, which you can select with C-c . (c-set-style). This properly handles case labels, long return expressions, and things like that. The comments at the top explain how to turn it on by default in Mozilla code. It may have some SpiderMonkey-isms in it; if you send me bug reports, I will split it into “Mozilla” and “SpiderMonkey” styles.
  • mercurial-queues.el, a major mode for editing Mercurial Queues series files, pushing, popping, and refreshing patches, and so on. In particular, the push and pop commands take care of refreshing any buffers visiting modified files. (This is currently slow if you have many buffers open, due to a shortcoming in vc‘s Mercurial support that makes refreshing a buffer take a significant fraction of a second. I have an unpolished workaround; if anyone besides me begins to use this and complains to me, then I’ll certainly finish it up and get it into the code.)
  • diff-find-mq-file.el, a quick hack to help ‘diff-goto-source‘ and ‘diff-apply-hunk‘, commands that jump from a hunk in a patch file to the place where that hunk would apply, find the file to patch when they’re invoked on a patch in a .hg/patches directory.

Happy Hacking!