Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
#!/usr/bin/tclsh
#
# attachgdb - version 2001jan17 - by Edrx (edrx@inx.com.br)
# GPL
#
# This script checks its parent process, then its grandparent process,
# etc, etc, until it finds one with a given name, "make", say; then it
# calls gnudoit to make the current emacs session attach a gdb to its
# pid. Note that sometimes (in some cases 50% of the times) gdb fails
# to attach to that pid, claiming "ptrace: no such process."; I don't
# know the cause of this, so be ready to run your gdbattach-calling
# program multiple times.
#
# The first parameter to this script is name of the program to attach
# gdb to, the others are passed literally to gdb; see "%opts" below.
#
# Note that we use the /proc/xxx/stat files, which are Linux-specific.
# (find-k22file "fs/proc/array.c" "static int get_stat(")
# (eeman "5 proc" "stat")


proc readfile {fname} {
  set f [open $fname r]; set s [read $f]; close $f
  return $s
}

proc ancestorpid {progname} {
  for {set dirid self} {$dirid!="0"} {set dirid $ppid}  {
    scan [readfile /proc/$dirid/stat] "%d %s %c %d" pid comm state ppid
    if {$comm=="($progname)"} {
      return $pid
    }
  }
  error "Process not found"
}

proc gnudoit {lispcode} {
  puts $lispcode
  puts [exec gnudoit $lispcode]
}

# (find-angg "eev-extras.el" "gdbk-mode")
proc gdbk-gdb {args} {
  gnudoit "(gdbk-gdb nil \"$args\")"
}

puts [join $argv]
eval [join $argv]




#Obsolete notes:
# set elisp0 {(gdb "gdb --silent %path %pid")}
# set path [lindex $argv 0]
# set opts [join [lrange $argv 1 end]]
# set pid [ancestorpid [file tail $path]]
# set elisp "gdb \"$opts $path $pid\""
# gnudoit $elisp