Replacing the GDB D patch with dfilt

Downs default_357-line at yahoo.de
Mon Sep 17 06:57:09 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The following modified version of dfilt (see the phobos std.demangle doc
for original source) with special handling of the GDB prompt allows for
dfilt to be used with gdb like so

gdb programname |dfilt

The source is

import std.stdio;
import std.ctype;
import std.demangle;

void writefl(char c) {
  writef(c); fflush(null);
}
void writefl(char[] c) {
  writef(c); fflush(null);
}

void mangprint(string line) {
  bool inword=false;
  char[] buffer;

  foreach (ch; line) {
    if (inword) {
      if (ch == '_' || isalnum(ch)) buffer ~= ch;
      else {
        inword = false;
        writefl(demangle(buffer)~ch);
      }
    } else {
      if (ch == '_' || isalpha(ch)) {
        inword=true;
        buffer=[ch];
      } else writefl(ch);
    }
  }
  if (inword) writefl(demangle(buffer));
  writefln;
}

int main() {
  char[] line;
  bool immediate=false;
  int c;

  while ((c = fgetc(stdin)) != EOF) {
    char ch=cast(char)c;
    if (immediate) {
      if (c == 10) {
        writefln;
        immediate=false;
      } else writefl(ch);
      continue;
    }
    if (c == 10) { mangprint(line); line=""; continue; }
    line ~= ch;
    if (line.length!<2 && line[$-2..$]==") ") { immediate=true;
writefl(line); line=""; continue; }
  }
  return 0;
}

Enjoy!
 --downs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG7oe1pEPJRr05fBERAuRUAJ9jd2P9uq6kQY+8CrXb1yYwaS6D6gCZAfb2
juWInY7VGoQE5hW7HqeTiIY=
=WJ1i
-----END PGP SIGNATURE-----



More information about the Digitalmars-d mailing list