Make pawndisasm display file names and line numbers
This commit is contained in:
parent
6cbc4203b5
commit
030be737b5
@ -77,4 +77,5 @@ ADD_EXECUTABLE(pawncc ${PAWNCC_SRCS})
|
|||||||
TARGET_LINK_LIBRARIES(pawncc pawnc)
|
TARGET_LINK_LIBRARIES(pawncc pawnc)
|
||||||
|
|
||||||
# The Pawn disassembler
|
# The Pawn disassembler
|
||||||
ADD_EXECUTABLE(pawndisasm pawndisasm.c)
|
SET(PAWNDISASM_SRCS pawndisasm.c ../amx/amxdbg.c ../amx/amx.c)
|
||||||
|
ADD_EXECUTABLE(pawndisasm ${PAWNDISASM_SRCS})
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "../amx/amx.h"
|
#include "../amx/amx.h"
|
||||||
|
#include "../amx/amxdbg.h"
|
||||||
|
|
||||||
static FILE *fpamx;
|
static FILE *fpamx;
|
||||||
static AMX_HEADER amxhdr;
|
static AMX_HEADER amxhdr;
|
||||||
@ -488,6 +489,10 @@ int main(int argc,char *argv[])
|
|||||||
int codesize,count;
|
int codesize,count;
|
||||||
cell *code,*cip;
|
cell *code,*cip;
|
||||||
OPCODE_PROC func;
|
OPCODE_PROC func;
|
||||||
|
AMX_DBG dbg;
|
||||||
|
int dbgloaded;
|
||||||
|
const char *filename;
|
||||||
|
long line,prevline;
|
||||||
|
|
||||||
if (argc<2 || argc>3) {
|
if (argc<2 || argc>3) {
|
||||||
printf("Usage: pawndisasm <input> [output]\n");
|
printf("Usage: pawndisasm <input> [output]\n");
|
||||||
@ -511,7 +516,11 @@ int main(int argc,char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
/* load debug info */
|
||||||
|
dbgloaded=(dbg_LoadInfo(&dbg, fpamx)==AMX_ERR_NONE);
|
||||||
|
|
||||||
/* load header */
|
/* load header */
|
||||||
|
fseek(fpamx,0,SEEK_SET);
|
||||||
fread(&amxhdr,sizeof amxhdr,1,fpamx);
|
fread(&amxhdr,sizeof amxhdr,1,fpamx);
|
||||||
if (amxhdr.magic!=AMX_MAGIC) {
|
if (amxhdr.magic!=AMX_MAGIC) {
|
||||||
printf("Not a valid AMX file\n");
|
printf("Not a valid AMX file\n");
|
||||||
@ -543,7 +552,16 @@ int main(int argc,char *argv[])
|
|||||||
/* browse through the code */
|
/* browse through the code */
|
||||||
cip=code;
|
cip=code;
|
||||||
codesize=amxhdr.dat-amxhdr.cod;
|
codesize=amxhdr.dat-amxhdr.cod;
|
||||||
|
prevline=0;
|
||||||
while (((unsigned char*)cip-(unsigned char*)code)<codesize) {
|
while (((unsigned char*)cip-(unsigned char*)code)<codesize) {
|
||||||
|
if (dbgloaded) {
|
||||||
|
dbg_LookupFile(&dbg,(cell)(cip-code)*sizeof(cell),&filename);
|
||||||
|
dbg_LookupLine(&dbg,(cell)(cip-code)*sizeof(cell),&line);
|
||||||
|
if (filename!=NULL && line != prevline) {
|
||||||
|
fprintf(fplist,"%s:%d\n",filename,line+1);
|
||||||
|
prevline=line;
|
||||||
|
}
|
||||||
|
} /* if */
|
||||||
func=opcodelist[(int)(*cip&0x0000ffff)].func;
|
func=opcodelist[(int)(*cip&0x0000ffff)].func;
|
||||||
cip+=func(fplist,cip+1,*cip,(cell)(cip-code)*sizeof(cell));
|
cip+=func(fplist,cip+1,*cip,(cell)(cip-code)*sizeof(cell));
|
||||||
} /* while */
|
} /* while */
|
||||||
@ -572,6 +590,10 @@ int main(int argc,char *argv[])
|
|||||||
name[0]='\0';
|
name[0]='\0';
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
if (dbgloaded) {
|
||||||
|
dbg_FreeInfo(&dbg);
|
||||||
|
} /* if */
|
||||||
|
|
||||||
free(code);
|
free(code);
|
||||||
fclose(fpamx);
|
fclose(fpamx);
|
||||||
fclose(fplist);
|
fclose(fplist);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user