基础调试命令 - u/ub/uf
在调试过程中难免会遇到需要反编译代码来分析逻辑的时候,在windbg中,需要反编译代码就要用到u/ub/uf这三个命令。本文这里分别介绍这三个命令各自的用途。
以下是一个quick sort的实例代码,将其编译成可执行文件,然后通过windbg运行。
#include <stdio.h> #include <string.h> #define MAXLINES 5000 #define MAXLEN 1000 #define ALLOCSIZE 10000 static char allocbuf[ALLOCSIZE]; static char *allocp = allocbuf; char *lineptr[MAXLINES]; int readlines(char *lineptr[], int nlines); void writelines(char *lineptr[], int nlines); void qsort(void *lineptr[], int left, int right, int(*comp)(void *, void *)); int numcmp(char *, char *); main(int argc, int *argv[]) { int nlines; int numeric = 0; if((argc > 1) && strcmp(argv[1], "-n")==0) numeric = 1; if((nlines = readlines(lineptr, MAXLINES)) >= 0){ qsort((void **) lineptr, 0, nlines-1, (int (*)(void*, void*))(numeric ? numcmp : strcmp)); writelines(lineptr, nlines); return 0; } else { printf("input too big to sort "); return 1; } } void qsort(void *v[], int left, int right, int (*comp)(void *, void *)) { int i, last; void swap(void *v[], int, int); if(left >= right) return; swap(v, left, (left+right)/2); last = left; for( i = left+1; i <= right; i++) if((*comp)(v[i], v[left]) < 0) swap(v, ++last, i); swap(v, left, last); qsort(v, left, last-1, comp); qsort(v, last+1, right, comp); } char *alloc(int n) { if(allocbuf + ALLOCSIZE - allocp >= n){ allocp += n; return allocp - n; } else return 0; }
int getline(char s[], int lim) { int c, i; i = 0; while(--lim > 0 && (c=getchar()) != EOF && c != ' ') s[i++] = c; if(c == ' ') s[i++] = c; s[i] = '