The Boston Diaries

The ongoing saga of a programmer who doesn't live in Boston, nor does he even like Boston, but yet named his weblog/journal “The Boston Diaries.”

Go figure.

Wednesday, August 22, 2018

I don't need no steeeenking debugger

I was still having troubles with lldb accepting breakpoints; the breakpoints were just not being hit. Thinking about the issue, it seemed to me that the code might be requesting a too large amount of memory and an easy eay to do that is to track all allocations made by Lua. It was easy enough to test:

static void *l_alloc(void *ud,void *ptr,size_t osize,size_t nsize)
{
  (void)ud;

  fprintf(stderr,"osize=%zu nsize=%zu\n",osize,nsize);

  if (nsize == 0)
  {
    free(ptr);
    return NULL;
  }
  else
    return realloc(ptr,nsize);
}

int main(int argc,char *argv[])
{
  /* ... */

  L = lua_newstate(l_alloc,NULL);

  /* ... */
  return 0;
}

Then it was a simple matter of running the program and check each allocation:

 ...
osize=0 nsize=64
osize=0 nsize=40
osize=0 nsize=64
osize=0 nsize=0
osize=0 nsize=64
osize=0 nsize=16
osize=0 nsize=64
osize=0 nsize=0
osize=0 nsize=160
osize=0 nsize=148
osize=0 nsize=64
osize=0 nsize=16
osize=16 nsize=32
osize=0 nsize=16
osize=0 nsize=64
osize=0 nsize=18446744073709551600
 ...

Hmmmmm

Okay, force a core dump we can examine:

static void *l_alloc(void *ud,void *ptr,size_t osize,size_t nsize)
{
  (void)ud;
  (void)osize;

  if (nsize > 10uL * 1024uL * 1024uL)
    abort(); /* dump core! */

  if (nsize == 0)
  {
    free(ptr);
    return NULL;
  }
  else
    return realloc(ptr,nsize);
}

And the problem is immedately resolved.

The Linux version used epoll() for events, while for whatever reason I don't remember, the Mac OS-X version used select() [Yes, I know that's a Linux reference and not a Mac OS-X reference, but the call is the same between the two systems, and I couldn't find a version of the Mac OS-X page online. —Sean], and that code path was … a bit problematic.

The fix was easy—use poll() for events. With that change, the code worked fine on Mac OS-X (not that we use Mac OS-X in production, but it makes it easy to test in development if it works on the Mac).

Obligatory Picture

An abstract representation of where you're coming from]

Obligatory Contact Info

Obligatory Feeds

Obligatory Links

Obligatory Miscellaneous

Obligatory AI Disclaimer

No AI was used in the making of this site, unless otherwise noted.

You have my permission to link freely to any entry here. Go ahead, I won't bite. I promise.

The dates are the permanent links to that day's entries (or entry, if there is only one entry). The titles are the permanent links to that entry only. The format for the links are simple: Start with the base link for this site: https://boston.conman.org/, then add the date you are interested in, say 2000/08/01, so that would make the final URL:

https://boston.conman.org/2000/08/01

You can also specify the entire month by leaving off the day portion. You can even select an arbitrary portion of time.

You may also note subtle shading of the links and that's intentional: the “closer” the link is (relative to the page) the “brighter” it appears. It's an experiment in using color shading to denote the distance a link is from here. If you don't notice it, don't worry; it's not all that important.

It is assumed that every brand name, slogan, corporate name, symbol, design element, et cetera mentioned in these pages is a protected and/or trademarked entity, the sole property of its owner(s), and acknowledgement of this status is implied.

Copyright © 1999-2024 by Sean Conner. All Rights Reserved.