####### # # E-scripts on the "anatomy" of compiled C programs # # Note 1: use the eev command (defined in eev.el) and the # ee alias (in my .zshrc) to execute parts of this file. # Executing this file as a whole makes no sense. # # Note 2: be VERY careful and make sure you understand what # you're doing. # # Note 3: If you use a shell other than zsh things like |& # and the for loops may not work. # # Note 4: I always run as root. # # Note 5: some parts are too old and don't work anymore. Some # never worked. # # Note 6: the definitions for the find-xxxfile commands are on my # .emacs. # # Note 7: if you see a strange command check my .zshrc -- it may # be defined there as a function or an alias. # # Note 8: the sections without dates are always older than the # sections with dates. # # This file is at # or at . # See also , # , # , # , # and . # ####### # «.gcc_libc_docs» (to "gcc_libc_docs") # «.asm_in_gcc» (to "asm_in_gcc") # «.hello-world-in-asm» (to "hello-world-in-asm") # «.elf-kickers» (to "elf-kickers") # «.elf-kickers-deb-src» (to "elf-kickers-deb-src") # «.c-to-EsSo» (to "c-to-EsSo") # «.easynasm» (to "easynasm") # «.nasm_crim1» (to "nasm_crim1") # «.gdb_and_C_types» (to "gdb_and_C_types") # «.cdecl» (to "cdecl") # «.c_eval» (to "c_eval") # «.dlopen» (to "dlopen") # «.dlopen-gdb» (to "dlopen-gdb") # «.gcc-v» (to "gcc-v") # «.libvforkwrap» (to "libvforkwrap") # «.LD_PRELOAD» (to "LD_PRELOAD") # «.gcc_source» (to "gcc_source") # «.glibc-src» (to "glibc-src") # «.ld.so» (to "ld.so") # «.regexps» (to "regexps") # «.system» (to "system") # «.edrxroot» (to "edrxroot") # «.biew» (to "biew") # «.dietlibc» (to "dietlibc") # «.uclibc» (to "uclibc") # «.uclibc-upstream» (to "uclibc-upstream") # «.newlib-deb-src» (to "newlib-deb-src") # «.newlib-upstream» (to "newlib-upstream") # «.tcc» (to "tcc") # «.tcc-deb-src» (to "tcc-deb-src") # «.nasm-upstream» (to "nasm-upstream") # «.K-and-R» (to "K-and-R") # «.stabs» (to "stabs") # «.eckelcpp» (to "eckelcpp") # «.warning» (to "warning") # «.alignment» (to "alignment") # «.stackdemo» (to "stackdemo") ##### # # gcc/libc docs # 2001feb06 # ##### # «gcc_libc_docs» (to ".gcc_libc_docs") # The libc info docs are MUCH better than the manpages. # (find-node "(libc)Top") # (find-node "(gcc)Top") # zcatinfo /usr/share/info/gcc > /tmp/gcc.info zcatinfo /usr/share/info/libc > /tmp/libc.info # # (find-fline "/tmp/gcc.info") # (find-fline "/tmp/libc.info") ##### # # asm in gcc # 2001feb08 # ##### # «asm_in_gcc» (to ".asm_in_gcc") # (find-htetfile "Assembly-HOWTO.gz") # (find-htetfile "Assembly-HOWTO.gz" "crt1.S") # (find-htetfile "Assembly-HOWTO.gz" "docs for GCC Inline Asm") # (find-node "(gcc)C Extensions") # (find-node "(gcc)Extended Asm") # (find-node "(gcc)Extended Asm" "with no outputs") # (find-node "(as)Index") # (find-node "(as)Pseudo Ops") # (find-node "(as)Syntax") # (find-node "(as)Preprocessing" "#APP") # (find-fline "/tmp/x.s") # (find-fline "/tmp/y.s") # (find-k22file "arch/i386/") # cd /tmp/ cat > x.c <<'---' int foo[] = {1, 2}; int bar() { return quux(3); } --- gcc -S x.c cat x.s # cat > y.c <<'---' int dummy() { /* __asm__(".data" : ".byte 0x12, 0x23" : ".text"); */ __asm__("\n.data\n" "\t.byte 0x12, 0x23\n" ".text\n" ::); } --- gcc -S y.c cat y.s # # (find-node "(as)Infix Ops") # (find-node "(as)Preprocessing") # (find-node "(gasp)Overview") # (find-node "(gcc)Overall Options" "`FILE.S'") ##### # # "hello, world" in asm # 2005out18 (thx to debiantux) # ##### # «hello-world-in-asm» (to ".hello-world-in-asm") # (find-htetfile "Assembly-HOWTO.gz" "6.2.3. GAS (hello.S)") # rm -Rv ~/usrc/asmtest/ mkdir ~/usrc/asmtest/ cd ~/usrc/asmtest/ cat > hello.S <<'%%%' .data # section declaration msg: .ascii "Hello, world!\n" # our dear string len = . - msg # length of our dear string .text # section declaration # we must export the entry point to the ELF linker or .global _start # loader. They conventionally recognize _start as their # entry point. Use ld -e foo to override the default. _start: # write our string to stdout movl $len,%edx # third argument: message length movl $msg,%ecx # second argument: pointer to message to write movl $1,%ebx # first argument: file handle (stdout) movl $4,%eax # system call number (sys_write) int $0x80 # call kernel # and exit movl $0,%ebx # first argument: exit code movl $1,%eax # system call number (sys_exit) int $0x80 # call kernel %%% as -o hello.o hello.S ld -s -o hello hello.o ./hello # ##### # # ELF kickers # 2000jun20 # ##### # «elf-kickers» (to ".elf-kickers") # http://www.muppetlabs.com/~breadbox/software/elfkickers.html # (find-shttpw3 "www.muppetlabs.com/~breadbox/software/elfkickers.html") # rm -Rv /usr/src/ELFkickers/ cd /usr/src/ tar -xvzf $S/ftp/ftp.muppetlabs.com/pub/software/ELFkickers.tar.gz cd /usr/src/ELFkickers/ cd /usr/src/ELFkickers/tiny/ ./factor 1232 # # (code-c-d "elfk" "/usr/src/ELFkickers/") # (find-elfkfile "") # (find-elfkfile "README") # (find-elfkfile "tiny/") # (find-elfkfile "tiny/factor.asm") # (find-elfkfile "tiny/factor.asm" "dynamic:") # (find-elfkfile "tiny/factor.asm" "") tar -tvzf $S/ftp/ftp.muppetlabs.com/pup/software/tiny.tar.gz # (code-c-d "muppet" "$S/http/www.muppetlabs.com/") # (find-muppetw3 "~breadbox/software/tiny/teensy.html") # (find-muppetw3 "~breadbox/software/tiny/home.html") # (find-muppetfile "~breadbox/software/ELF.txt") # (find-muppetfile "~breadbox/software/ELF.txt" "\nPART 2") # (find-k22file "fs/binfmt_elf.c") # (find-k22file "include/linux/elf.h") # (find-k22file "include/linux/elfcore.h") # (find-k22file "include/asm-i386/elf.h") # (find-k22file "include/config/binfmt/elf.h") ##### # # elfkickers (from the debian sources) # 2007oct27 # ##### # «elf-kickers-deb-src» (to ".elf-kickers-deb-src") # http://ftp.debian.org/debian/pool/main/e/elfkickers/ # http://ftp.debian.org/debian/pool/main/e/elfkickers/elfkickers_2.0a-2.dsc # http://ftp.debian.org/debian/pool/main/e/elfkickers/elfkickers_2.0a-2.diff.gz # http://ftp.debian.org/debian/pool/main/e/elfkickers/elfkickers_2.0a.orig.tar.gz # rm -Rv ~/usrc/elfkickers/ mkdir ~/usrc/elfkickers/ cd $S/http/ftp.debian.org/debian/pool/main/e/elfkickers/ cp -v elfkickers_2.0a* ~/usrc/elfkickers/ cd ~/usrc/elfkickers/ dpkg-source -sn -x elfkickers_2.0a-2.dsc cd ~/usrc/elfkickers/elfkickers-2.0a/ dpkg-buildpackage -us -uc -b -rfakeroot |& tee odb # # (find-fline "~/usrc/elfkickers/")  (eepitch-shell) cd ~/usrc/elfkickers/ sudo dpkg -i *.deb # # (code-c-d "elfkickers" "~/usrc/elfkickers/elfkickers-2.0a/") # (find-elfkickersfile "") # (find-elfkickersfile "tiny/") ##### # # .c -> .[EsSo] # 2000jun20 # ##### # «c-to-EsSo» (to ".c-to-EsSo") # (find-gccnode "Overall Options") # rm -Rv /tmp/c/ mkdir /tmp/c/ cd /tmp/c/ cat > demo.c <<'---' #include main() { int sum, i; for(sum=0, i=0; i<10; ++i) sum += i; printf("Sum: %d\n", sum); } --- gcc -E demo.c > demo.i gcc -S demo.c gcc -S demo.c -g -o demog.s gcc -c demo.c gcc -c demo.c -g -o demog.o gcc demo.c -o demo -v |& tee ogv gcc demo.c -o demog -g -v |& tee ogvg diff ogv ogvg # ##### # # objdump # 2000jun24 # ##### # (find-status "binutils") # (find-vldifile "binutils.list") # (find-fline "/usr/doc/binutils/") # (find-status "binutils-doc") # (find-vldifile "binutils-doc.list") # (find-fline "/usr/doc/binutils-doc/") # (find-man "1 objdump") # (find-node "(binutils)objdump") # (find-es "fortho" "eforth") cd /usr/src/eforth-1.0e/ objdump -Ssax eforth |& tee ~/o # (find-fline "~/o") ##### # # nasm # 2000jun23 # ##### # (find-status "nasm") # (find-vldifile "nasm.list") # (find-fline "/usr/doc/nasm/") # (find-node "(nasm)Top") # (find-node "(nasm)Chapter 6" "`elf'") # (find-node "(nasm)Section 8.1.1" "ELF, though, the leading underscore") # (find-node "(nasm)Appendix A") ##### # # easynasm # 2000jul06 # ##### # «easynasm» (to ".easynasm") # (find-es "fortho" "perpol") # rm -Rv /usr/src/easynasm/ cd /usr/src/ tar -xvzf $S/http/www.boswa.com/education/programming/easynasm.tgz cd /usr/src/easynasm/ # (find-fline "/usr/src/easynasm/") # (find-fline "/usr/src/easynasm/readme.txt") ./easynasm hello.asm && ./hello ./easynasm hi.asm && ./hi ./easynasm simple.asm && ./simple # ##### # # using nasm to write crim1 programs # 2000jul08 # ##### # «nasm_crim1» (to ".nasm_crim1") # (find-node "(nasm)Section 6.1.1" "dd label") # (find-node "(nasm)Chapter 8" "Interfacing to 32-bit C Programs") # (find-node "(nasm)Section 3.2" "`DB' and friends") # (find-node "(nasm)Section 4.1.1" "%define") # (find-node "(nasm)Section 4.2" "%macro") cd /usr/share/info/ zcatinfo /usr/share/info/nasm > /tmp/nasm # (find-fline "/tmp/nasm") # cat > /tmp/demo.asm <<'---' %macro d2 1 db ((%1) - _f0) >> 8 db ((%1) - _f0) & 0xFF %endmacro %define H_COL 0xFF %define H_RSR 0xFE %define H_CON 0xFD %define H_TO 0xFC %define H_AT 0xFB %define SF_EXIT 0xFF %define SF_PLUS 0xFE %define SF_2DUP 0xFD %define COUNT _f0 + 0xFA00 %define TYPE _f0 + 0xFA01 %define CR _f0 + 0xFA02 %define STO _f0 + 0xFA03 %define TOS _f0 + 0xFA04 _f0: AT_FOO: db H_AT TO_FOO: db H_TO FOO: db H_CON dw 0x1234 SSTRGOBBLE: db H_COL d2 STO d2 COUNT db SF_2DUP db SF_PLUS d2 TOS db SF_EXIT DOTQUO: db H_RSR SDOTQUO: db H_COL d2 SSTRGOBBLE d2 TYPE db SF_EXIT DDQUO: db H_RSR SDDQUO: db H_COL d2 SDOTQUO d2 CR d2 SDOTQUO db SF_EXIT DEMO: db H_COL d2 DDQUO db 5, 'Hello' db 5, 'There' db SF_EXIT --- nasm -f bin -o /tmp/demo /tmp/demo.asm nasm -f elf -o /tmp/demoelf /tmp/demo.asm objdump -xasf /tmp/demoelf # # (find-enode "Editing Binary Files") # (hexl-find-file "/tmp/demo") # 0000: fbfcfd 3412 # 0005: ff fa03 fa00 fd fe fa04 ff # 000f: feff 0005 fa01 ff # 0016: feff 0010 fa02 0010 ff # 001f: ff 0016 0548656c6c6f 055468657265 ff ##### # # regexps in C # 2000jun18 # ##### # (find-node "(libc)POSIX Regexp Compilation") # (find-node "(libc)Matching POSIX Regexps") # (eeman "3 regcomp") # int regcomp(regex_t *preg, const char *regex, int cflags); # int regexec(const regex_t *preg, const char *string, # size_t nmatch, regmatch_t pmatch[], int eflags); # cat > /tmp/ctmp.c <<'---' #include #include int main(int argc, char **argv) { regex_t r; regmatch_t pmatch[10]; printf("%d\n", regcomp(&r, argv[1], 0)); printf("%d\n", regexec(&r, argv[2], 10, pmatch, 0)); return 0; } --- gcc -E /tmp/ctmp.c > /tmp/ctmp.E gcc -Wall -o /tmp/ctmp /tmp/ctmp.c \ && /tmp/ctmp ab cabbab # # (find-es "debian0" "boot-floppies-src") # (find-bffile "utilities/busybox/regexp.c") # (find-bffile "utilities/busybox/regexp.h") ##### # # Using gdb to inspect C types # 2000oct14 # ##### # «gdb_and_C_types» (to ".gdb_and_C_types") # cd /tmp/ cat > m.c <<'---' #include double (*m)[10]; main() { int i, j, n; m = malloc(8*20*10); for(i=0, n=0; i<20; ++i) for(j=0; j<10; ++j, ++n) m[i][j] = n; for(i=0, n=0; i<20; ++i) for(j=0; j<10; ++j, ++n) printf("%f ", m[i][j]); } --- gcc -g -o m m.c ./m cat > $EEG <<'---' br main run ptype m ptype *m ptype **m --- # # Now you may either invoke gdb directly with, say, gdb /tmp/m < $EEG # or from Emacs, using my .gdbinit and gdbk-mode, with: # (progn (gdb "gdb /tmp/m") (gdbk-mode)) # For more info: # (find-angg ".gdbinit") # (find-angg ".emacs" "gdbk-mode") ##### # # cdecl # 2000dec18 # ##### # «cdecl» (to ".cdecl") # (find-angg ".emacs" "find-cdecl") # (find-es "swig" "C-types-as-strings") # (find-status "cdecl") # (find-vldifile "cdecl.list") # (find-vldifile "cdecl.preinst") # (find-vldifile "cdecl.postrm") # (find-fline "/usr/doc/cdecl/") # (find-status "cutils") # (find-vldifile "cutils.list") # (find-udfile "cutils/") # (find-node "(cutils)Top") # (find-node "(cutils)cdecl/cundecl examples") # (find-man "1 cdecl" "EXAMPLES") # cat > $EEG <<'---' declare fptab as array of pointer to function returning pointer to char declare fptab as array of ptr to func ret ptr to char explain char *(*fptab[])() exit --- eeg cdecl # cdecl.cutils <<'---' char *s; void (*signal(int sig, void (*func)(int)))(int); (const char *)s; (void (*)(int))signal_function; const char *const *argv; --- cundecl <<'---' declare s as pointer to char; declare x as function (fmt as pointer to const char, ...) returning int; cast s into pointer to const char; cast f into pointer to function (int) returning void; --- # ##### # # A zsh function to execute a string as C code # 2000dec18 # ##### # «c_eval» (to ".c_eval") # function ccc () { echo "#include \nmain(int argc, char **argv){ $1 }" > /tmp/ccc.c gcc -o /tmp/ccc /tmp/ccc.c && /tmp/ccc $*[2,-1] rm /tmp/ccc{,.c} } ccc 'int cc, c=0, l=0; while( (cc=fgetc(stdin)) != EOF ) { c++; l+=(cc==10)?1:0; } printf("character: %d\nlines: %d\n",c,l); ' < /etc/passwd # ##### # # dlopen (with thx to ctrl-alt-dels) # 2000dec22 # ##### # «dlopen» (to ".dlopen") # (find-man "3 dlopen") # (find-man "3 dlopen" "EXAMPLE") # cd /tmp/ cat > so.c <<'---' #include void distant() { printf("Hello from a distant place.\n"); } --- gcc -g -Wall -shared -o so.so so.c # i386-uclibc-linux-gcc -g -Wall -shared -o so.so so.c cat > x.c <<'---' #include #include int main() { void *libptr; void (*f)(); printf("After an effort of concentration you hear a\n"); libptr=dlopen("/tmp/so.so", RTLD_LAZY); f=dlsym(libptr, "distant"); /* printf("%x %x\n", libptr, f); */ f(); printf("Bye now.\n"); return 0; } --- gcc -g -Wall -ldl -o x x.c # i386-uclibc-linux-gcc -g -Wall -ldl -o x x.c ./x # # «dlopen-gdb» (to ".dlopen-gdb") # gdb will happily enter into dynamically loaded modules... # Run the `eegud-gdb' hyperlink here and single-step with M-s or M-n. # (find-eev "e/tutorial.e" "eegud") br main run # (ee-once (eeb-gdb-start "/tmp/" "x")) # ##### # # understanding how gcc builds an executable (with gcc -v) # 2001jan18 # ##### # «gcc-v» (to ".gcc-v") # cd /tmp/ cat > x.c <<'---' #include int main() { printf("Hello!\n"); return 0; } --- gcc -v -o x x.c |& tee /tmp/o # (find-fline "/tmp/o") # # After some cleaning... # (find-node "(gcc)Option Summary") # (find-node "(gcc)Overall Options") cd /tmp/ /usr/lib/gcc-lib/i386-linux/2.95.2/cpp -lang-c \ -D__GNUC__=2 -D__GNUC_MINOR__=95 -D__ELF__ -Dunix -D__i386__ -Dlinux \ -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux \ -A"system(posix)" \ -Wall -A"cpu(i386)" -A"machine(i386)" \ -Di386 -D__i386 -D__i386__ x.c x.i /usr/lib/gcc-lib/i386-linux/2.95.2/cc1 x.i \ -quiet -dumpbase x.c -Wall -version -o x.s as -V -Qy -o x.o x.s cat > /tmp/ld <<'---' #!/bin/sh echo echo ld $* exec /usr/bin/ld $* --- chmod 755 /tmp/ld # (find-angg ".zshrc" "strace") PATH=/tmp:$PATH \ vfwstrace -f -q -e trace=file -o ~/s \ /usr/lib/gcc-lib/i386-linux/2.95.2/collect2 -m elf_i386 \ -dynamic-linker /lib/ld-linux.so.2 \ -o x \ /usr/lib/crt1.o /usr/lib/crti.o \ /usr/lib/gcc-lib/i386-linux/2.95.2/crtbegin.o \ -L/usr/lib/gcc-lib/i386-linux/2.95.2 \ x.o \ -lgcc -lc -lgcc \ /usr/lib/gcc-lib/i386-linux/2.95.2/crtend.o /usr/lib/crtn.o rm -v /tmp/ld # # sort ~/s | l # (find-fline "~/s") grep open ~/s | grep -v ENOENT | getstrings | sort | uniq | tee ~/o # (find-fline "~/o") # #I am quite sure that the resulting "x" was built from these files... # /usr/lib/crt1.o # /usr/lib/crti.o # /usr/lib/crtn.o # /usr/lib/gcc-lib/i386-linux/2.95.2/crtbegin.o # /usr/lib/gcc-lib/i386-linux/2.95.2/crtend.o # /tmp/x.o #Not so sure about these ones... # /lib/ld-linux.so.2 # /lib/libc.so.6 # /usr/lib/gcc-lib/i386-linux/2.95.2/libgcc.a # /usr/lib/libc.so #And I don't have a clue if these ones are are used: # /usr/lib/libbfd-2.9.5.0.37.so # /usr/lib/libc_nonshared.a # /lib/libdl.so.2 #Packages owning those files: # binutils: /usr/lib/libbfd-2.9.5.0.37.so # gcc: /usr/lib/gcc-lib/i386-linux/2.95.2/crtbegin.o # gcc: /usr/lib/gcc-lib/i386-linux/2.95.2/crtend.o # gcc: /usr/lib/gcc-lib/i386-linux/2.95.2/libgcc.a # libc6: /lib/ld-linux.so.2 # libc6: /lib/libc.so.6 # libc6: /lib/libdl.so.2 # libc6-dev: /usr/lib/crt1.o # libc6-dev: /usr/lib/crti.o # libc6-dev: /usr/lib/crtn.o # libc6-dev: /usr/lib/libc.so # libc6-dev: /usr/lib/libc_nonshared.a # (find-gccfile "odrb" "crtbegin.o") # (find-gccfile "odrb" "crtend.o") ##### # # libvforkwrap, as Linux doesn't strace over vforks # 2000jan19 # ##### # «libvforkwrap» (to ".libvforkwrap") # (find-angg ".zshrc" "strace") # (find-deblistsw3 "debian-mentors-0007/msg00089.html") # rm -Rv /usr/src/libvforkwrap-0.1/ cd /usr/src/ tar -xvzf $S/http/lists.debian.org/debian-mentors-0007/bin00000.bin cd /usr/src/libvforkwrap-0.1/ make # # «LD_PRELOAD» (to ".LD_PRELOAD") # (find-libvfwfile "") # (find-libvfwfile "dpkg-genbuilddeps" "LD_PRELOAD") # (find-man "8 ld.so" "LD_PRELOAD") # (find-man "1 strace" "-e trace=file") # Sample usage (these examples use fake files!): LD_PRELOAD="/usr/src/libvforkwrap-0.1/libvforkwrap.so.0 $LD_PRELOAD" \ strace -q -f -e trace=file -o ~/s \ program_that_used_to_call_vfork args # (find-angg ".zshrc" "strace") vfwstrace -q -f -e trace=file -o ~/s \ program_that_used_to_call_vfork args ##### # # gcc source # 2000dec23 # ##### # «gcc_source» (to ".gcc_source") # pdsc $SDEBIAN/dists/potato/main/source/devel/gcc_2.95.2-13.dsc cd /usr/src/gcc-2.95.2/ debian/rules unpack |& tee odru cd /usr/src/gcc-2.95.2/src/ find .* * | sort > .files # # Making just crtbegin.o, crtend.o, and libgcc.a: cd /usr/src/gcc-2.95.2/ debian/rules configure |& tee odrc cd /usr/src/gcc-2.95.2/build/libiberty/ make libiberty.a |& tee om cd /usr/src/gcc-2.95.2/build/gcc/ make crtbegin.o crtend.o |& tee omcrt make libgcc.a |& tee omlibgcc # (find-gccfile "build/gcc/") # (find-gccfile "build/gcc/Makefile" "crtbegin.o:") # (find-gccfile "build/gcc/Makefile" "libgcc.a:") # (find-gccfile "build/gcc/omcrt") # (find-gccfile "build/gcc/omlibgcc") # cd /usr/src/gcc-2.95.2/ (time debian/rules binary) |& tee odrb # 30 mins and it broke with an error at src/libio/filebuf.cc... # # (code-c-d "gcc" "/usr/src/gcc-2.95.2/") # (code-c-d "gcc0" "/usr/src/gcc0-2.95.2/") # (find-gccfile "src/gcc/crtstuff.c") # (find-gccfile "src/gcc/config/i386/crtdll.h") # (find-gccfile "src/gcc/config/i386/t-crtpic") # (find-gccfile "src/gcc/config/i386/t-crtstuff") # (find-gccfile "debian/") # (find-gccfile "src/") # (find-gccfile "src/.files") # (find-gccfile "odrb") # (find-gccfile "odrb" "crtbegin.o" ) # (find-gccfile "odrb" "libgcc.a" ) ##### # # glibc (libc6) source # ##### # «glibc-src» (to ".glibc-src") # (find-glibcfile "debian/control") apti kernel-headers-2.2.15 # pdsc $SDEBIAN/dists/potato/main/source/libs/glibc_2.1.3-10.dsc cd /usr/src/glibc-2.1.3/ # (find-glibcfile "debian/") # (find-glibcfile "debian/README") # debian/rules unpack |& tee odru debian/rules configure |& tee odrc cd /usr/src/glibc-2.1.3/glibc-2.1.3/ find * -type f | sort > .files # glimpseindex -H . -F < .files cd /usr/src/glibc-2.1.3/ # debian/rules binary |& tee odrb # make -C /usr/src/glibc-2.1.3/i386-linux/obj PARALLELMFLAGS="" |& tee om # (cd /usr/src/glibc-2.1.3/i386-linux/obj/; make) |& tee om cd /usr/src/glibc-2.1.3/glibc-2.1.3/ make -r objdir=/usr/src/glibc-2.1.3/i386-linux/obj all |& tee om # (find-glibcsfile "om") # (find-glibcofile "") # (find-glibcofile "Makefile") # (find-glibcfile "debian/rules") # (find-glibcfile "debian/rules" "arch_packages") # (find-glibcfile "debian/sysdeps/") # (find-glibcfile "debian/sysdeps/sysdeps.mk") # glibcglimpse crt1 # # Files that I'm trying to learn how to make: # libc6: /lib/ld-linux.so.2 # libc6: /lib/libc.so.6 # libc6: /lib/libdl.so.2 # libc6-dev: /usr/lib/crt1.o # libc6-dev: /usr/lib/crti.o # libc6-dev: /usr/lib/crtn.o # libc6-dev: /usr/lib/libc.so # libc6-dev: /usr/lib/libc_nonshared.a # (code-c-d "glibc" "/usr/src/glibc-2.1.3/") # (code-c-d "glibcs" "/usr/src/glibc-2.1.3/glibc-2.1.3/") # (code-c-d "glibco" "/usr/src/glibc-2.1.3/i386-linux/obj/") # (code-c-d "glibcd" "/usr/src/glibc-2.1.3/debian/") # (find-glibcfile "") # (find-glibcfile "log-build-i386-linux") # (find-glibcfile "debian/") # (find-glibcfile "debian/control") # (find-glibcsfile "FAQ") # (find-glibcsfile "csu/") # (find-glibcsfile "csu/Makefile") # (find-glibcsfile "csu/Makefile" "C startup code") # (find-glibcofile "") ##### # # ld.so # 2000jan19 # ##### # «ld.so» (to ".ld.so") # pdsc $SDEBIAN/dists/potato/main/source/base/ld.so_1.9.11-9.dsc cd /usr/src/ld.so-1.9.11/ find * | sort > .files # # (find-ldsofile "") # (find-ldsofile "test/") ##### # # Regexps # 2001nov14 # ##### # «regexps» (to ".regexps") # (find-node "(libc)Regular Expressions") # (find-node "(libc)POSIX Regexp Compilation") # (find-node "(libc)POSIX Regexp Compilation" "Function: int regcomp") # (find-man "7 regex") # (find-man "7 regex" "Henry Spencer's") # (find-man "3 regcomp") # (find-fline "/usr/include/regex.h") # (find-fline "/usr/include/regexp.h") # (find-fline "/usr/include/regex.h" "#define RE_SYNTAX_EMACS 0") # (find-fline "/usr/include/regex.h" "extern int re_match") # (find-angg "lua-4.0/src/libdllua/lrexlib-new.c") # (find-angg "lua-4.0/src/libdllua/lrexlib.c") # (find-fline "~/lua-4.0/src/libdllua/lrexlib.c" "res = regcomp") res = regcomp(rp, pattern, REG_EXTENDED | REG_PEND); # (find-man "3 regcomp") # (find-man "3 regcomp" "regcomp returns zero") # (find-es "emacs" "faces") # (set-text-properties (point) (mark) nil) # (find-node "(libc)Parsing of Integers") # rm -Rv /tmp/regex/ mkdir /tmp/regex/ cd /tmp/regex/ cat > regtest.c <<'---' #include #include #include int main(int argc, const char **argv) { regex_t *preg; char *regex, *string, errbuf[80]; int errcode, r, cflags, nmatch, eflags; regmatch_t pmatch[10]; preg = malloc(sizeof(regex_t)); cflags = atoi(argv[1]); eflags = atoi(argv[2]); regex = argv[3]; string = argv[4]; errcode = regcomp(preg, regex, cflags); if (errcode) { r = regerror(errcode, preg, errbuf, sizeof(errbuf)); printf("%s\n", errbuf); exit(1); } nmatch = preg->re_nsub; r = regexec(preg, string, nmatch, pmatch, eflags); if (r) exit(2); printf("found!\n"); return 0; } --- gcc -Wall -g -o regtest regtest.c cd /tmp/regex/ ./regtest 0 0 foo banafooba # # (gdbk-gdb 'do-eeg-bounded "/tmp/regex/regtest") set args 0 0 'f(o)o' banafooba br main run # ##### # # system # 2002feb08 # ##### # «system» (to ".system") # (find-node "(libc)Running a Command") # (find-node "(libc)Program Arguments") # (find-fline "~/tmp/lua-4.0/src/lua/lua.c" "int main") # cd ~/tmp/ cat > test.c <<'---' #include "stdlib.h" int main(int argc, char *argv[]) { system("cd /tmp; ls"); } --- gcc -o test test.c ./test # # «edrxroot» (to ".edrxroot") # (find-node "(libc)Process Persona") # (find-node "(sh-utils)whoami invocation") # (find-node "(sh-utils)id invocation") # (find-man "2 chmod") # I want to copy edrxroot to /edrx and to chmod it to 4755: chmod -v --reference=/bin/ping /bin/ping cd ~/tmp/ cat > edrxroot.c <<'---' #include "stdlib.h" int main(int argc, char *argv[]) { system("test $(id -rnu) = ochs && cd /home/ochs/edrx && exec ./run-zsh"); } --- gcc -o edrxroot edrxroot.c cp -v edrxroot /tmp/ ./edrxroot # ##### # # biew # 2003jul01 # ##### # «biew» (to ".biew") # (find-available "biew") # (find-status "biew") # (find-vldifile "biew.list") # (find-udfile "biew/") ##### # # steps in a "for" loop # 2001jul26 # ##### # cat > /tmp/for.c <<'---' #include #define P printf main() { int i; for (P("for_init"),i=0; P(" test\n"),i<4; P(" incr"),++i) { P(" code"); } return 0; } --- gcc -o /tmp/for /tmp/for.c /tmp/for # ##### # # Linker scripts # 2001mar01 # ##### # (find-node "(ld)Simple Example") # (find-fline "/usr/lib/ldscripts/") # (find-status "binutils") # (find-vldifile "binutils.list") # (find-fline "/usr/doc/binutils/") ##### # # dietlibc # 2004oct10 # ##### # «dietlibc» (to ".dietlibc") # (find-status "dietlibc-doc") # (find-vldifile "dietlibc-doc.list") # (find-udfile "dietlibc-doc/") # (find-status "dietlibc-dev") # (find-vldifile "dietlibc-dev.list") # (find-udfile "dietlibc-dev/") # (find-status "dietlibc") # (find-vldifile "dietlibc.list") # (find-udfile "dietlibc/") # (find-man "1 diet") # rm -Rv ~/usrc/dietlibc/ mkdir ~/usrc/dietlibc/ cd ~/usrc/dietlibc/ # rm -Rv ~/usrc/dietlibc/dietlibc-0.27/ mkdir ~/usrc/dietlibc/ cd ~/usrc/dietlibc/ apt-get source dietlibc # # (code-c-d "dietlibc" "~/usrc/dietlibc/dietlibc-0.27/") # (find-dietlibcfile "") # (find-dietlibcfile "lib/") # (find-dietlibcfile "lib/__v_printf.c") # (find-dietlibcfile "libstdio/") # (find-dietlibcfile "test/") ##### # # uclibc # 2005mar05 # ##### # «uclibc» (to ".uclibc") # (find-status "libuclibc-dev") # (find-vldifile "libuclibc-dev.list") # (find-udfile "libuclibc-dev/") # (find-status "uclibc-toolchain") # (find-vldifile "uclibc-toolchain.list") # (find-udfile "uclibc-toolchain/") # (find-status "libuclibc0") # (find-vldifile "libuclibc0.list") # (find-udfile "libuclibc0/") # http://ftp.debian.org/debian/pool/main/u/uclibc/ # rm -Rv ~/bigsrc/uclibc/ mkdir ~/bigsrc/uclibc/ cd ~/bigsrc/uclibc/ dpkg-source -x $S/http/ftp.debian.org/debian/pool/main/u/uclibc/uclibc_0.9.26-cvs20040816-5.1.dsc ~/bigsrc/uclibc/uclibc-0.9.26-cvs20040816/ find * -type f -name '*.[chS]' | sort > .files.chS # # (code-c-d "uclibc" "~/bigsrc/uclibc/uclibc-0.9.26-cvs20040816/") # (find-uclibcfile "") # (find-uclibcfile "libc/stdlib/") # (find-uclibcfile "libc/stdio/") # (find-uclibcfile "libc/stdio/vfprintf.c") ##### # # uclibc from the upstream sources # 2005nov10 # ##### # «uclibc-upstream» (to ".uclibc-upstream") # http://www.uclibc.org/ # http://www.uclibc.org/downloads/ # http://www.uclibc.org/downloads/uClibc-0.9.29.tar.bz2 # rm -Rv ~/bigsrc/uClibc-0.9.29/ mkdir ~/bigsrc/uClibc-0.9.29/ cd ~/bigsrc/uClibc-0.9.29/ tar -C ~/bigsrc/ -xvjf \ $S/http/www.uclibc.org/downloads/uClibc-0.9.29.tar.bz2 find * -type d | sort > .dirs find * -type f -name '*.[chS]' | sort > .files.chS # (find-uclibcsh "cd libpthread/linuxthreads/sysdeps/; ls | paste -s -d'|'") egrep -v '/(alpha|arm|bfin|cris|frv|m68k|mips|nios|nios2|powerpc|pthread|sh|sh64|sparc|v850|x86_64)/' < .files.chS > .files.chS- egrep -v '/(e1|h8300|i960|microblaze)/' < .files.chS- > .files.chS-- etags $(cat .files.chS--) # # (code-c-d "uclibc" "~/bigsrc/uClibc-0.9.29/") # (find-uclibcfile "") # (find-uclibctag "strncmp") ##### # # newlib (from the debian sources) # 2008sep02 # ##### # «newlib-deb-src» (to ".newlib-deb-src") # http://ftp.debian.org/debian/pool/main/n/newlib/ # http://ftp.debian.org/debian/pool/main/n/newlib/newlib_1.16.0-3.dsc # http://ftp.debian.org/debian/pool/main/n/newlib/newlib_1.16.0-3.diff.gz # http://ftp.debian.org/debian/pool/main/n/newlib/newlib_1.16.0.orig.tar.gz # sudo apt-get build-dep newlib # rm -Rv ~/bigsrc/newlib/ mkdir ~/bigsrc/newlib/ cd $S/http/ftp.debian.org/debian/pool/main/n/newlib/ cp -v newlib_1.16.0* ~/bigsrc/newlib/ cd ~/bigsrc/newlib/ dpkg-source -sn -x newlib_1.16.0-3.dsc cd ~/bigsrc/newlib/newlib-1.16.0/ dpkg-buildpackage -us -uc -b -rfakeroot |& tee odb # # (find-fline "~/bigsrc/newlib/")  (eepitch-shell) cd ~/bigsrc/newlib/ sudo dpkg -i *.deb # # (code-c-d "newlib" "~/bigsrc/newlib/newlib-1.16.0/") # (find-newlibfile "") ##### # # newlib - upstream version # 2008sep02 # ##### # «newlib-upstream» (to ".newlib-upstream") # (find-es "lua5" "elua") # (find-es "emacs" "emacs-from-cvs") # ftp://sources.redhat.com/pub/newlib/index.html # http://sources.redhat.com/newlib/download.html # rm -Rv ~/bigsrc/newlib/ mkdir ~/bigsrc/newlib/ cd ~/bigsrc/newlib/ tar -xvzf ~/tmp/newlib-cvs.tgz cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/src login # {enter "anoncvs" as the password} cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/src co newlib |& tee oc tar -cvzf ~/tmp/newlib-cvs.tgz src/ # rm -Rv ~/bigsrc/newlib/ mkdir ~/bigsrc/newlib/ cd ~/bigsrc/newlib/ tar -xvzf ~/tmp/newlib-cvs.tgz cd ~/bigsrc/newlib/src/ CC=gcc ./configure |& tee oc make |& tee om make all-hello |& tee omah # # (code-c-d "newlib" "~/bigsrc/newlib/src/") # (find-newlibfile "") # (find-newlibfile "Makefile") # (find-newlibfile "Makefile" "info: do-info") # (find-newlibfile "Makefile" "\ndist:\n") # (find-newlibfile "Makefile" "\nall-build-bison:") # (find-newlibfile "README") # (find-newlibsh "CC=gcc ./configure --help") # http://elua.berlios.de/tut_gcc_arm.html # http://www.gnu.org/software/binutils/ # http://www.gnu.org/software/gcc/ # http://www.gnu.org/software/gcc/gcc-4.3/ # ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.3.2/ # ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.3.2/gcc-4.3.2.tar.bz2  (eepitch-shell)  (eepitch-kill)  (eepitch-shell) sudo apt-get install flex bison libgmp3-dev libmpfr-dev autoconf texinfo Next, decide where you want to install your toolchain. They generally go in /usr/local/, so I'm going to assume /usr/local/cross-arm for this tutorial. To save yourself some typing, set this path into a shell variable: # export TOOLPATH=/usr/local/cross-arm export TOOLPATH=/tmp/local-cross-arm mkdir $TOOLPATH/ : Step 1: binutils This is the easiest step: unpack, configure, build. $ tar xvfj binutils-2.17.tar.bz2 $ cd binutils-2.17 $ mkdir build $ cd build $ ../configure --target=arm-elf --prefix=$TOOLPATH --enable-interwork --enable-multilib --with-gnu-as --with-gnu-ld --disable-nls $ make all $ sudo make install $ export PATH=${TOOLPATH}/bin:$PATH ##### # # binutils upstream # 2008sep06 # ##### # http://ftp.gnu.org/gnu/binutils/binutils-2.18.tar.bz2 # rm -Rv ~/bigsrc/binutils-2.18/ tar -C ~/bigsrc/ -xvjf \ $S/http/ftp.gnu.org/gnu/binutils/binutils-2.18.tar.bz2 cd ~/bigsrc/binutils-2.18/ export TOOLPATH=/tmp/local-cross-arm mkdir $TOOLPATH/ cd ~/bigsrc/binutils-2.18/ mkdir build/ cd build/ ../configure \ --target=arm-elf --prefix=$TOOLPATH --enable-interwork \ --enable-multilib --with-gnu-as --with-gnu-ld --disable-nls \ |& tee oc make all |& tee oma # sudo make install # export PATH=${TOOLPATH}/bin:$PATH # export TOOLPATH=/tmp/local-cross-arm mkdir $TOOLPATH/ # (code-c-d "binutils" "~/bigsrc/binutils-2.18/") # (find-binutilsfile "") # (find-binutilsfile "build/") # (find-binutilsfile "build/oc") # (find-binutilsfile "build/oma") # (find-binutilsfile "build/oma" "checking for makeinfo") # (find-binutilsfile "configure" "For an installed makeinfo") # (find-binutilsfile "build/config.log") # (find-binutilsfile "build/config.log" "checking for makeinfo") # (find-binutilsfile "build/config.log" "MAKEINFO=") # (find-binutilsfile "build/config.log" "\nMAKEINFO=") # (find-binutilsfile "build/config.status") # (find-binutilsfile "build/config.status" "s,@MAKEINFO@,") # (find-status "texinfo") # (find-vldifile "texinfo.list") # (find-udfile "texinfo/") ##### # # tcc # 2006jul07 # ##### # «tcc» (to ".tcc") # (find-status "tcc") # (find-vldifile "tcc.list") # (find-udfile "tcc/") # (find-node "(tcc)Top") # (find-udfile "tcc/examples/ex1.c") # (find-udfile "tcc/examples/ex2.c") # (find-udfile "tcc/examples/ex3.c") # (find-udfile "tcc/examples/ex4.c") # (find-udfile "tcc/examples/ex5.c") # (find-man "1 tcc") ##### # # tcc (from the debian sources) # 2007dec20 # ##### # «tcc-deb-src» (to ".tcc-deb-src") # http://ftp.debian.org/debian/pool/main/t/tcc/ # http://ftp.debian.org/debian/pool/main/t/tcc/tcc_0.9.23-4.dsc # http://ftp.debian.org/debian/pool/main/t/tcc/tcc_0.9.23-4.diff.gz # http://ftp.debian.org/debian/pool/main/t/tcc/tcc_0.9.23.orig.tar.gz # rm -Rv ~/usrc/tcc/ mkdir ~/usrc/tcc/ cd $S/http/ftp.debian.org/debian/pool/main/t/tcc/ cp -v tcc_0.9.23* ~/usrc/tcc/ cd ~/usrc/tcc/ dpkg-source -sn -x tcc_0.9.23-4.dsc cd ~/usrc/tcc/tcc-0.9.23/ dpkg-buildpackage -us -uc -b -rfakeroot |& tee odb # # (code-c-d "tcc" "~/usrc/tcc/tcc-0.9.23/") # (find-tccfile "") # (find-tccfile "tcc.c") # (find-tccfile "examples/") # (find-node "(gcc)Macro Varargs") # (find-node "(cpp)Macro Varargs") # (find-node "(cpp)Stringification") # eegcc <<<' #define stringify(x) #x #define FOO 0x99 main() { printf(stringify(FOO) "\n"); } ' eec # ##### # # nasm (upstream) # 2007feb06 # ##### # «nasm-upstream» (to ".nasm-upstream") # http://ufpr.dl.sourceforge.net/sourceforge/nasm/nasm-0.98.39.tar.bz2 # (code-c-d "nasm" "~/usrc/nasm-0.98.39/") # (find-nasmfile "") # rm -Rv ~/usrc/nasm-0.98.39/ tar -C ~/usrc/ -xvjf \ $S/http/ufpr.dl.sourceforge.net/sourceforge/nasm/nasm-0.98.39.tar.bz2 cd ~/usrc/nasm-0.98.39/ ./configure |& tee oc make |& tee om # ##### # # K&R # 2007jul28 # ##### # «K-and-R» (to ".K-and-R") # rm -Rv ~/usrc/the-c-programming-language/ tar -C ~/usrc/ -xvzf \ ~/books/the-c-programming-language.tar.gz cd ~/usrc/the-c-programming-language/ # # (code-c-d "kandr" "~/usrc/the-c-programming-language/") # (find-kandrfile "") # (find-kandrw3m "kandr.html") # (find-kandrw3m "chapter5.html") # (find-kandrw3m "chapter5.html#s5.3" "pa = &a[0];") There is one difference between an array name and a pointer that must be kept in mind. A pointer is a variable, so pa=a and pa++ are legal. But an array name is not a variable; constructions like a=pa and a++ are illegal. When an array name is passed to a function, what is passed is the location of the initial element. Within the called function, this argument is a local variable, and so an array name parameter is a pointer, that is, a variable containing an address. We can use this fact to write another version of strlen, which computes the length of a string. # (find-kandrw3m "chapter6.html") # (find-kandrw3m "chapter6.html#s6.3") # (find-kandrw3m "chapter6.html#s6.3" "sizeof keytab / sizeof(keytab[0])") ##### # # stabs # 2007aug31 # ##### # «stabs» (to ".stabs") # (find-es "davinci") # Can I use stabs to discover the sizeofs and offsets of structs? # cd /tmp/ cat > foo.c <<'%%%' #include struct s { int a; int b; }; int main(void){ struct s t; t.a = 1; t.b = 2; printf("Here: %i and %i\n", t.a, t.b); return 0; } %%% gcc -g -S -o foo.s foo.c gcc -gstabs -S -o foo.st foo.c gcc -g -c -o foo.o foo.c gcc -g -o foo foo.c ./foo #  (eepitch-comint "gdb-foo" "gdb /tmp/foo")  (eepitch-kill)  (eepitch-comint "gdb-foo" "gdb /tmp/foo") ptype struct s quit # (find-sh "cd /tmp/; objdump -xasf foo.o" "NEEDED") # (find-sh "cd /tmp/; objdump -xasf foo.o" "Contents of section .debug_str:") # (find-fline "/tmp/") # (find-node "(stabs)Flow" "`-g'") # (find-node "(stabs)Stabs Format") # (find-node "(stabs)Assembly Code") # (find-es "anatocc" "c-to-EsSo") # (find-fline "/tmp/foo.s" ".string\t\"unsigned char\"") # (find-fline "/tmp/foo.s") # (find-fline "/tmp/foo.st") # (find-gccnode "Debugging Options" "`-gstabs'") # (find-sh "cd /tmp/; gcc -v -g -c -o foo.o foo.c") # (find-status "binutils") # (find-vldifile "binutils.list") # (find-udfile "binutils/") # (find-status "binutils-doc") # (find-vldifile "binutils-doc.list") # (find-udfile "binutils-doc/") # (find-node "(as)Stab") ##### # # Bruce Eckel: Thinking in C++ # 2007aug31 # ##### # «eckelcpp» (to ".eckelcpp") # http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html # http://www.web42.com/eckel/TICPP-2nd-ed-Vol-one.zip # http://www.web42.com/eckel/TICPP-2nd-ed-Vol-two.zip # rm -Rv ~/usrc/eckelcpp1/ rm -Rv ~/usrc/eckelcpp2/ mkdir ~/usrc/eckelcpp1/ mkdir ~/usrc/eckelcpp2/ unzip -d ~/usrc/eckelcpp1/ \ $S/http/www.web42.com/eckel/TICPP-2nd-ed-Vol-one.zip unzip -d ~/usrc/eckelcpp2/ \ $S/http/www.web42.com/eckel/TICPP-2nd-ed-Vol-two.zip cd ~/usrc/eckelcpp1/ unzip TIC2Vone-distribution/TICPP-2nd-ed-Vol-one-code.zip unzip TIC2Vone-distribution/TICPP-2nd-ed-Vol-one-html.zip # (find-sh "cmp --help") for i in CompilerData.txt RevisionHistory.txt; do cmp $i TIC2Vone-distribution/html/$i && rm -v TIC2Vone-distribution/html/$i done mv -iv TIC2Vone-distribution/html/* . # # (code-c-d "eckelcpp1" "~/usrc/eckelcpp1/") # (code-c-d "eckelcpp2" "~/usrc/eckelcpp2/") # (find-eckelcpp1file "") # (find-eckelcpp2file "") # (find-eckelcpp1w3m "Contents.html") # (find-eckelcpp2w3m "html/Contents.htm") ##### # # #warning # 2007sep12 # ##### # «warning» (to ".warning") # (find-status "cpp-doc") # (find-vldifile "cpp-doc.list") # (find-udfile "cpp-doc/") # (find-status "cpp-4.1-doc") # (find-vldifile "cpp-4.1-doc.list") # (find-udfile "cpp-4.1-doc/") # (find-node "(cpp)Diagnostics" "`#warning'") ##### # # alignment (in structs) # 2007sep12 # ##### # «alignment» (to ".alignment") # (find-es "davinci" "peek.lua:doc") # (find-gccnode "Warning Options" "`-Wpacked'") # (find-gccnode "Variable Attributes" "`aligned (ALIGNMENT)'") # (find-gccnode "Variable Attributes" "\n\n`packed'") ##### # # stackdemo # 2007dec20 # ##### # «stackdemo» (to ".stackdemo") # (to "c-to-EsSo") # (find-node "(gdb)Sample Session" "`backtrace'") # (find-node "(gdb)Frames") # (find-node "(gdb)Frames" "`frame ARGS'") # (find-node "(gdb)Frames" "`select-frame'") # (find-node "(gdb)Backtrace") # (find-node "(gdb)Registers") # (find-node "(gdb)Machine Code" "\n`disassemble'\n") # rm -Rv /tmp/stackdemo/ mkdir /tmp/stackdemo/ cd /tmp/stackdemo/ cat > sd.c <<'%%%' int d(int d1, int d2, ...) { int d3=3, d4=4; return 'd'; } int c(int c1, int c2, ...) { int c3=3, c4=4; d(1, 2); return 'c'; } int b(int b1, int b2, ...) { int b3=3, b4=4; c(1, 2); return 'b'; } int a(int a1, int a2, ...) { int a3=3, a4=4; b(1, 2); return 'a'; } int main() { a(10, 20, 30, 40); return 0; } %%% gcc -O0 -g -S -o sd.s sd.c gcc -O0 -g -o sd sd.c # # (find-fline "/tmp/stackdemo/sd.c") # (find-fline "/tmp/stackdemo/sd.s") (defun eepitch-gdb-sd () (eepitch-gdb "*gud-sd*" "gdb --annotate=3 --quiet /tmp/stackdemo/sd")) (defun eepitch-gdb-sd-kill () (eepitch-gdb-kill "*gud-sd*"))  (eepitch-gdb-sd)  (eepitch-gdb-sd-kill)  (eepitch-gdb-sd) br d run bt p &d1 p &d2 p &d3 p &d4 p d frame disassemble frame 3 p &a1 p &a2 p &a2+1 p *(&a1) p *(&a2) p *(&a2+1) p *(&a2+2) # (find-fline "/tmp/stackdemo/sd.s" "\nd:") p $fp frame 0 # _________ _________ _________ _________ __________ # | | | | | | # | strack | strack | strack | strack | strack | # | frame | frame | frame | frame | frame | # | for d | for c | for b | for a | for main | # |_________|_________|_________|_________|__________| # # This is the stack frame for a, in details: _________ _________ __________ __________ | | | | | | a1 | a2 | *(&a2+1) | *(&a2+2) | | (=10) | (=20) | (=30) | (=40) | |_________|_________|__________|__________| # http://en.wikipedia.org/wiki/Executable_and_Linkable_Format # (find-node "(binutils)readelf") # (find-node "(as)") # (find-node "(binutils)") # (find-node "(ld)") # (find-node "(binutils)c++filt") # (find-node "(binutils)Index" "* demangling") # (find-node "(binutils)nm") # (find-node "(binutils)ar") # (find-node "(binutils)ranlib") # (find-node "(ld)Options" "`-Wl,'") # (find-node "(ld)Options" "`-E'") # (find-node "(ld)Options" "`-lARCHIVE'") # (find-man "1 ld") http://www.cs.princeton.edu/~rs/Algs3.c1-4/code.txt source for crt1, etc? dynamic linking? ldd? Linking path? stabs? elf? How does the kernel reads elf files? And files with other "magic"? Environment? Home dir? # Local Variables: # coding: raw-text-unix # ee-delimiter-hash: "\n#\n" # ee-delimiter-percent: "\n%\n" # ee-anchor-format: "«%s»" # End: