winedbg: Attach the source files to a given process, and unload them at process end.

This commit is contained in:
Eric Pouech 2008-04-30 21:26:57 +02:00 committed by Alexandre Julliard
parent 5d90e60ed5
commit 95f2d367b3
4 changed files with 71 additions and 48 deletions

View file

@ -132,7 +132,7 @@ command:
| tFRAME tNUM { stack_set_frame($2); } | tFRAME tNUM { stack_set_frame($2); }
| tSHOW tDIR { source_show_path(); } | tSHOW tDIR { source_show_path(); }
| tDIR pathname { source_add_path($2); } | tDIR pathname { source_add_path($2); }
| tDIR { source_nuke_path(); } | tDIR { source_nuke_path(dbg_curr_process); }
| tCOND tNUM { break_add_condition($2, NULL); } | tCOND tNUM { break_add_condition($2, NULL); }
| tCOND tNUM expr { break_add_condition($2, $3); } | tCOND tNUM expr { break_add_condition($2, $3); }
| tSOURCE pathname { parser($2); } | tSOURCE pathname { parser($2); }

View file

@ -224,6 +224,11 @@ struct dbg_process
unsigned next_bp; unsigned next_bp;
struct dbg_delayed_bp* delayed_bp; struct dbg_delayed_bp* delayed_bp;
int num_delayed_bp; int num_delayed_bp;
struct open_file_list* source_ofiles;
char* search_path;
char source_current_file[MAX_PATH];
int source_start_line;
int source_end_line;
struct dbg_process* next; struct dbg_process* next;
struct dbg_process* prev; struct dbg_process* prev;
}; };
@ -369,7 +374,8 @@ extern void source_list(IMAGEHLP_LINE* src1, IMAGEHLP_LINE* src2, in
extern void source_list_from_addr(const ADDRESS64* addr, int nlines); extern void source_list_from_addr(const ADDRESS64* addr, int nlines);
extern void source_show_path(void); extern void source_show_path(void);
extern void source_add_path(const char* path); extern void source_add_path(const char* path);
extern void source_nuke_path(void); extern void source_nuke_path(struct dbg_process* p);
extern void source_free_files(struct dbg_process* p);
/* stack.c */ /* stack.c */
extern void stack_info(void); extern void stack_info(void);

View file

@ -22,10 +22,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef PATH_MAX
#define PATH_MAX MAX_PATH
#endif
#include "debugger.h" #include "debugger.h"
struct open_file_list struct open_file_list
@ -38,20 +34,13 @@ struct open_file_list
unsigned int* linelist; unsigned int* linelist;
}; };
static struct open_file_list* source_ofiles;
static char* search_path; /* = NULL; */
static char source_current_file[PATH_MAX];
static int source_start_line = -1;
static int source_end_line = -1;
void source_show_path(void) void source_show_path(void)
{ {
const char* ptr; const char* ptr;
const char* next; const char* next;
dbg_printf("Search list:\n"); dbg_printf("Search list:\n");
for (ptr = search_path; ptr; ptr = next) for (ptr = dbg_curr_process->search_path; ptr; ptr = next)
{ {
next = strchr(ptr, ';'); next = strchr(ptr, ';');
if (next) if (next)
@ -68,10 +57,10 @@ void source_add_path(const char* path)
unsigned size; unsigned size;
size = strlen(path) + 1; size = strlen(path) + 1;
if (search_path) if (dbg_curr_process->search_path)
{ {
unsigned pos = strlen(search_path) + 1; unsigned pos = strlen(dbg_curr_process->search_path) + 1;
new = HeapReAlloc(GetProcessHeap(), 0, search_path, pos + size); new = HeapReAlloc(GetProcessHeap(), 0, dbg_curr_process->search_path, pos + size);
if (!new) return; if (!new) return;
new[pos - 1] = ';'; new[pos - 1] = ';';
strcpy(&new[pos], path); strcpy(&new[pos], path);
@ -82,13 +71,13 @@ void source_add_path(const char* path)
if (!new) return; if (!new) return;
strcpy(new, path); strcpy(new, path);
} }
search_path = new; dbg_curr_process->search_path = new;
} }
void source_nuke_path(void) void source_nuke_path(struct dbg_process* p)
{ {
HeapFree(GetProcessHeap(), 0, search_path); HeapFree(GetProcessHeap(), 0, p->search_path);
search_path = NULL; p->search_path = NULL;
} }
static void* source_map_file(const char* name, HANDLE* hMap, unsigned* size) static void* source_map_file(const char* name, HANDLE* hMap, unsigned* size)
@ -115,7 +104,7 @@ static struct open_file_list* source_search_open_file(const char* name)
{ {
struct open_file_list* ol; struct open_file_list* ol;
for (ol = source_ofiles; ol; ol = ol->next) for (ol = dbg_curr_process->source_ofiles; ol; ol = ol->next)
{ {
if (strcmp(ol->path, name) == 0) break; if (strcmp(ol->path, name) == 0) break;
} }
@ -131,7 +120,7 @@ static BOOL source_locate_file(const char* srcfile, char* path)
strcpy(path, srcfile); strcpy(path, srcfile);
found = TRUE; found = TRUE;
} }
else if (search_path) else if (dbg_curr_process->search_path)
{ {
const char* spath; const char* spath;
@ -142,12 +131,34 @@ static BOOL source_locate_file(const char* srcfile, char* path)
if (!spath) spath = strchr(spath, '/'); if (!spath) spath = strchr(spath, '/');
if (!spath) break; if (!spath) break;
spath++; spath++;
found = SearchPathA(search_path, spath, NULL, MAX_PATH, path, NULL); found = SearchPathA(dbg_curr_process->search_path, spath, NULL, MAX_PATH, path, NULL);
} }
} }
return found; return found;
} }
static struct open_file_list* source_add_file(const char* name, const char* realpath)
{
struct open_file_list* ol;
size_t sz, nlen;
sz = sizeof(*ol);
nlen = strlen(name) + 1;
if (realpath) sz += strlen(realpath) + 1;
ol = HeapAlloc(GetProcessHeap(), 0, sz + nlen);
if (!ol) return NULL;
strcpy(ol->path = (char*)(ol + 1), name);
if (realpath)
strcpy(ol->real_path = ol->path + nlen, realpath);
else
ol->real_path = NULL;
ol->next = dbg_curr_process->source_ofiles;
ol->nlines = 0;
ol->linelist = NULL;
ol->size = 0;
return dbg_curr_process->source_ofiles = ol;
}
static int source_display(const char* sourcefile, int start, int end) static int source_display(const char* sourcefile, int start, int end)
{ {
char* addr; char* addr;
@ -158,7 +169,7 @@ static int source_display(const char* sourcefile, int start, int end)
char* pnt; char* pnt;
int rtn; int rtn;
HANDLE hMap; HANDLE hMap;
char tmppath[PATH_MAX]; char tmppath[MAX_PATH];
/* /*
* First see whether we have the file open already. If so, then * First see whether we have the file open already. If so, then
@ -212,14 +223,7 @@ static int source_display(const char* sourcefile, int start, int end)
* OK, I guess the user doesn't really want to see it * OK, I guess the user doesn't really want to see it
* after all. * after all.
*/ */
ol = HeapAlloc(GetProcessHeap(), 0, sizeof(*ol)); ol = source_add_file(sourcefile, NULL);
ol->path = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(sourcefile) + 1), sourcefile);
ol->real_path = NULL;
ol->next = source_ofiles;
ol->nlines = 0;
ol->linelist = NULL;
ol->size = 0;
source_ofiles = ol;
dbg_printf("Unable to open file '%s'\n", tmppath); dbg_printf("Unable to open file '%s'\n", tmppath);
return FALSE; return FALSE;
} }
@ -227,14 +231,7 @@ static int source_display(const char* sourcefile, int start, int end)
/* /*
* Create header for file. * Create header for file.
*/ */
ol = HeapAlloc(GetProcessHeap(), 0, sizeof(*ol)); ol = source_add_file(sourcefile, tmppath);
ol->path = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(sourcefile) + 1), sourcefile);
ol->real_path = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(tmppath) + 1), tmppath);
ol->next = source_ofiles;
ol->nlines = 0;
ol->linelist = NULL;
ol->size = 0;
source_ofiles = ol;
addr = source_map_file(tmppath, &hMap, &ol->size); addr = source_map_file(tmppath, &hMap, &ol->size);
if (addr == (char*)-1) return FALSE; if (addr == (char*)-1) return FALSE;
@ -310,7 +307,7 @@ void source_list(IMAGEHLP_LINE* src1, IMAGEHLP_LINE* src2, int delta)
sourcefile = NULL; sourcefile = NULL;
if (src1 && src1->FileName) sourcefile = src1->FileName; if (src1 && src1->FileName) sourcefile = src1->FileName;
if (!sourcefile && src2 && src2->FileName) sourcefile = src2->FileName; if (!sourcefile && src2 && src2->FileName) sourcefile = src2->FileName;
if (!sourcefile) sourcefile = source_current_file; if (!sourcefile) sourcefile = dbg_curr_process->source_current_file;
/* /*
* Now figure out the line number range to be listed. * Now figure out the line number range to be listed.
@ -323,12 +320,12 @@ void source_list(IMAGEHLP_LINE* src1, IMAGEHLP_LINE* src2, int delta)
{ {
if (delta < 0) if (delta < 0)
{ {
end = source_start_line; end = dbg_curr_process->source_start_line;
start = end + delta; start = end + delta;
} }
else else
{ {
start = source_end_line; start = dbg_curr_process->source_end_line;
end = start + delta; end = start + delta;
} }
} }
@ -340,10 +337,10 @@ void source_list(IMAGEHLP_LINE* src1, IMAGEHLP_LINE* src2, int delta)
*/ */
source_display(sourcefile, start, end); source_display(sourcefile, start, end);
if (sourcefile != source_current_file) if (sourcefile != dbg_curr_process->source_current_file)
strcpy(source_current_file, sourcefile); strcpy(dbg_curr_process->source_current_file, sourcefile);
source_start_line = start; dbg_curr_process->source_start_line = start;
source_end_line = end; dbg_curr_process->source_end_line = end;
} }
void source_list_from_addr(const ADDRESS64* addr, int nlines) void source_list_from_addr(const ADDRESS64* addr, int nlines)
@ -364,3 +361,16 @@ void source_list_from_addr(const ADDRESS64* addr, int nlines)
&disp, &il)) &disp, &il))
source_list(&il, NULL, nlines); source_list(&il, NULL, nlines);
} }
void source_free_files(struct dbg_process* p)
{
struct open_file_list* ofile;
struct open_file_list* ofile_next;
for (ofile = p->source_ofiles; ofile; ofile = ofile_next)
{
ofile_next = ofile->next;
HeapFree(GetProcessHeap(), 0, ofile->linelist);
HeapFree(GetProcessHeap(), 0, ofile);
}
}

View file

@ -302,6 +302,11 @@ struct dbg_process* dbg_add_process(const struct be_process_io* pio, DWORD pid,
memset(p->bp, 0, sizeof(p->bp)); memset(p->bp, 0, sizeof(p->bp));
p->delayed_bp = NULL; p->delayed_bp = NULL;
p->num_delayed_bp = 0; p->num_delayed_bp = 0;
p->source_ofiles = NULL;
p->search_path = NULL;
p->source_current_file[0] = '\0';
p->source_start_line = -1;
p->source_end_line = -1;
p->next = dbg_process_list; p->next = dbg_process_list;
p->prev = NULL; p->prev = NULL;
@ -331,6 +336,8 @@ void dbg_del_process(struct dbg_process* p)
HeapFree(GetProcessHeap(), 0, p->delayed_bp[i].u.symbol.name); HeapFree(GetProcessHeap(), 0, p->delayed_bp[i].u.symbol.name);
HeapFree(GetProcessHeap(), 0, p->delayed_bp); HeapFree(GetProcessHeap(), 0, p->delayed_bp);
source_nuke_path(p);
source_free_files(p);
if (p->prev) p->prev->next = p->next; if (p->prev) p->prev->next = p->next;
if (p->next) p->next->prev = p->prev; if (p->next) p->next->prev = p->prev;
if (p == dbg_process_list) dbg_process_list = p->next; if (p == dbg_process_list) dbg_process_list = p->next;