winedbg
Eric Pouech
eric.pouech at wanadoo.fr
Fri Aug 30 14:07:05 CDT 2002
Eric Pouech a écrit :
>
> Fabi found another bug in winedbg:
> while loading some source file, pointed to by MSVC debug information,
> winedbg was trying to load them thru the unix API
> this patch does the same work thru the Win32 API
>
> A+
this time with the patch attached
-------------- next part --------------
Name: wd_src
ChangeLog: now loading source files thru Win32 API
License: X11
GenDate: 2002/08/30 19:05:02 UTC
ModifiedFiles: debugger/source.c
AddedFiles:
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/debugger/source.c,v
retrieving revision 1.24
diff -u -u -r1.24 source.c
--- debugger/source.c 22 Jul 2002 20:33:25 -0000 1.24
+++ debugger/source.c 30 Aug 2002 19:03:16 -0000
@@ -106,96 +106,109 @@
listhead = NULL;
}
-static
-int
-DEBUG_DisplaySource(char * sourcefile, int start, int end)
+static void* DEBUG_MapFile(const char* name, HANDLE* hMap, unsigned* size)
{
- char * addr;
- char buffer[1024];
- int fd;
- int i;
- struct open_filelist * ol;
- int nlines;
- char * basename = NULL;
- char * pnt;
- int rtn;
- struct searchlist * sl;
- struct stat statbuf;
- int status;
- char tmppath[PATH_MAX];
-
- /*
- * First see whether we have the file open already. If so, then
- * use that, otherwise we have to try and open it.
- */
- for(ol = ofiles; ol; ol = ol->next)
- {
- if( strcmp(ol->path, sourcefile) == 0 )
- {
- break;
- }
- }
+ HANDLE hFile;
- if( ol == NULL )
- {
- /*
- * Try again, stripping the path from the opened file.
- */
- basename = strrchr(sourcefile, '\\' );
- if ( !basename )
- basename = strrchr(sourcefile, '/' );
- if ( !basename )
- basename = sourcefile;
- else
- basename++;
+ hFile = CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (hFile == INVALID_HANDLE_VALUE) return (void*)-1;
+ if (size != NULL && (*size = GetFileSize(hFile, NULL)) == -1) return (void*)-1;
+ *hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
+ CloseHandle(hFile);
+ if (!*hMap) return (void*)-1;
+ return MapViewOfFile(*hMap, FILE_MAP_READ, 0, 0, 0);
+}
- for(ol = ofiles; ol; ol = ol->next)
- {
- if( strcmp(ol->path, basename) == 0 )
- {
- break;
- }
- }
+static void DEBUG_UnmapFile(void* addr, HANDLE hMap)
+{
+ UnmapViewOfFile(addr);
+ CloseHandle(hMap);
+}
- }
+static struct open_filelist* DEBUG_SearchOpenFile(const char* name)
+{
+ struct open_filelist* ol;
- if( ol == NULL )
+ for (ol = ofiles; ol; ol = ol->next)
{
- /*
- * Crapola. We need to try and open the file.
- */
- status = stat(sourcefile, &statbuf);
- if( status != -1 )
- {
- strcpy(tmppath, sourcefile);
- }
- else if( (status = stat(basename, &statbuf)) != -1 )
- {
- strcpy(tmppath, basename);
- }
- else
- {
- for(sl = listhead; sl; sl = sl->next)
- {
- strcpy(tmppath, sl->path);
- if( tmppath[strlen(tmppath)-1] != '/' )
- {
- strcat(tmppath, "/");
- }
- /*
- * Now append the base file name.
- */
- strcat(tmppath, basename);
-
- status = stat(tmppath, &statbuf);
- if( status != -1 )
- {
- break;
- }
- }
+ if (strcmp(ol->path, name) == 0) break;
+ }
+ return ol;
+}
- if( sl == NULL )
- {
+static
+int
+DEBUG_DisplaySource(char * sourcefile, int start, int end)
+{
+ char* addr;
+ int i;
+ struct open_filelist* ol;
+ int nlines;
+ char* basename = NULL;
+ char* pnt;
+ int rtn;
+ struct searchlist* sl;
+ HANDLE hMap;
+ DWORD status;
+ char tmppath[PATH_MAX];
+
+ /*
+ * First see whether we have the file open already. If so, then
+ * use that, otherwise we have to try and open it.
+ */
+ ol = DEBUG_SearchOpenFile(sourcefile);
+
+ if ( ol == NULL )
+ {
+ /*
+ * Try again, stripping the path from the opened file.
+ */
+ basename = strrchr(sourcefile, '\\' );
+ if ( !basename )
+ basename = strrchr(sourcefile, '/' );
+ if ( !basename )
+ basename = sourcefile;
+ else
+ basename++;
+
+ ol = DEBUG_SearchOpenFile(basename);
+ }
+
+ if ( ol == NULL )
+ {
+ /*
+ * Crapola. We need to try and open the file.
+ */
+ status = GetFileAttributes(sourcefile);
+ if ( status != -1 )
+ {
+ strcpy(tmppath, sourcefile);
+ }
+ else if ( (status = GetFileAttributes(basename)) != -1 )
+ {
+ strcpy(tmppath, basename);
+ }
+ else
+ {
+ for (sl = listhead; sl; sl = sl->next)
+ {
+ strcpy(tmppath, sl->path);
+ if ( tmppath[strlen(tmppath)-1] != '/' && tmppath[strlen(tmppath)-1] != '\\' )
+ {
+ strcat(tmppath, "/");
+ }
+ /*
+ * Now append the base file name.
+ */
+ strcat(tmppath, basename);
+
+ status = GetFileAttributes(tmppath);
+ if ( status != -1 ) break;
+ }
+
+ if ( sl == NULL )
+ {
if (DEBUG_InteractiveP)
{
char zbuf[256];
@@ -204,13 +217,13 @@
*/
sprintf(zbuf, "Enter path to file '%s': ", sourcefile);
DEBUG_ReadLine(zbuf, tmppath, sizeof(tmppath));
-
- if( tmppath[strlen(tmppath)-1] == '\n' )
+
+ if ( tmppath[strlen(tmppath)-1] == '\n' )
{
tmppath[strlen(tmppath)-1] = '\0';
}
-
- if( tmppath[strlen(tmppath)-1] != '/' )
+
+ if ( tmppath[strlen(tmppath)-1] != '/' )
{
strcat(tmppath, "/");
}
@@ -218,127 +231,112 @@
* Now append the base file name.
*/
strcat(tmppath, basename);
-
- status = stat(tmppath, &statbuf);
+
+ status = GetFileAttributes(tmppath);
}
- if( status == -1 )
- {
- /*
- * OK, I guess the user doesn't really want to see it
- * after all.
- */
- ol = (struct open_filelist *) DBG_alloc(sizeof(*ol));
- ol->path = DBG_strdup(sourcefile);
- ol->real_path = NULL;
- ol->next = ofiles;
- ol->nlines = 0;
- ol->linelist = NULL;
- ofiles = ol;
- DEBUG_Printf(DBG_CHN_MESG,"Unable to open file %s\n", tmppath);
- return FALSE;
- }
- }
- }
- /*
- * Create header for file.
- */
- ol = (struct open_filelist *) DBG_alloc(sizeof(*ol));
- ol->path = DBG_strdup(sourcefile);
- ol->real_path = DBG_strdup(tmppath);
- ol->next = ofiles;
- ol->nlines = 0;
- ol->linelist = NULL;
- ol->size = statbuf.st_size;
- ofiles = ol;
-
- /*
- * Now open and map the file.
- */
- fd = open(tmppath, O_RDONLY);
- if( fd == -1 )
- {
- return FALSE;
- }
-
- addr = mmap(0, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if( addr == (char *) -1 )
- {
- return FALSE;
- }
-
- /*
- * Now build up the line number mapping table.
- */
- ol->nlines = 1;
- pnt = addr;
- while(pnt < addr + ol->size )
- {
- if( *pnt++ == '\n' )
- {
- ol->nlines++;
- }
- }
-
- ol->nlines++;
- ol->linelist = (unsigned int*) DBG_alloc( ol->nlines * sizeof(unsigned int) );
-
- nlines = 0;
- pnt = addr;
- ol->linelist[nlines++] = 0;
- while(pnt < addr + ol->size )
- {
- if( *pnt++ == '\n' )
- {
- ol->linelist[nlines++] = pnt - addr;
- }
- }
- ol->linelist[nlines++] = pnt - addr;
-
+ else
+ {
+ status = -1;
+ strcpy(tmppath, sourcefile);
+ }
+
+ if ( status == -1 )
+ {
+ /*
+ * OK, I guess the user doesn't really want to see it
+ * after all.
+ */
+ ol = (struct open_filelist *) DBG_alloc(sizeof(*ol));
+ ol->path = DBG_strdup(sourcefile);
+ ol->real_path = NULL;
+ ol->next = ofiles;
+ ol->nlines = 0;
+ ol->linelist = NULL;
+ ofiles = ol;
+ DEBUG_Printf(DBG_CHN_MESG,"Unable to open file %s\n", tmppath);
+ return FALSE;
+ }
+ }
+ }
+ /*
+ * Create header for file.
+ */
+ ol = (struct open_filelist *) DBG_alloc(sizeof(*ol));
+ ol->path = DBG_strdup(sourcefile);
+ ol->real_path = DBG_strdup(tmppath);
+ ol->next = ofiles;
+ ol->nlines = 0;
+ ol->linelist = NULL;
+ ol->size = 0;
+ ofiles = ol;
+
+ addr = DEBUG_MapFile(tmppath, &hMap, &ol->size);
+ if ( addr == (char *) -1 )
+ {
+ return FALSE;
+ }
+ /*
+ * Now build up the line number mapping table.
+ */
+ ol->nlines = 1;
+ pnt = addr;
+ while (pnt < addr + ol->size )
+ {
+ if ( *pnt++ == '\n' )
+ {
+ ol->nlines++;
+ }
+ }
+
+ ol->nlines++;
+ ol->linelist = (unsigned int*) DBG_alloc( ol->nlines * sizeof(unsigned int) );
+
+ nlines = 0;
+ pnt = addr;
+ ol->linelist[nlines++] = 0;
+ while(pnt < addr + ol->size )
+ {
+ if( *pnt++ == '\n' )
+ {
+ ol->linelist[nlines++] = pnt - addr;
+ }
+ }
+ ol->linelist[nlines++] = pnt - addr;
+
}
- else
+ else
{
- /*
- * We know what the file is, we just need to reopen it and remap it.
- */
- fd = open(ol->real_path, O_RDONLY);
- if( fd == -1 )
- {
- return FALSE;
- }
-
- addr = mmap(0, ol->size, PROT_READ, MAP_PRIVATE, fd, 0);
- if( addr == (char *) -1 )
- {
- return FALSE;
- }
+ addr = DEBUG_MapFile(ol->real_path, &hMap, NULL);
+ if ( addr == (char *) -1 )
+ {
+ return FALSE;
+ }
}
-
- /*
- * All we need to do is to display the source lines here.
- */
- rtn = FALSE;
- for(i=start - 1; i <= end - 1; i++)
+ /*
+ * All we need to do is to display the source lines here.
+ */
+ rtn = FALSE;
+ for (i = start - 1; i <= end - 1; i++)
{
- if( i < 0 || i >= ol->nlines - 1)
+ char buffer[1024];
+
+ if (i < 0 || i >= ol->nlines - 1)
{
- continue;
+ continue;
}
-
- rtn = TRUE;
- memset(&buffer, 0, sizeof(buffer));
- if( ol->linelist[i+1] != ol->linelist[i] )
+
+ rtn = TRUE;
+ memset(&buffer, 0, sizeof(buffer));
+ if ( ol->linelist[i+1] != ol->linelist[i] )
{
- memcpy(&buffer, addr + ol->linelist[i],
- (ol->linelist[i+1] - ol->linelist[i]) - 1);
+ memcpy(&buffer, addr + ol->linelist[i],
+ (ol->linelist[i+1] - ol->linelist[i]) - 1);
}
- DEBUG_Printf(DBG_CHN_MESG,"%d\t%s\n", i + 1, buffer);
+ DEBUG_Printf(DBG_CHN_MESG,"%d\t%s\n", i + 1, buffer);
}
-
- munmap(addr, ol->size);
- close(fd);
-
- return rtn;
-
+
+ DEBUG_UnmapFile(addr, hMap);
+ return rtn;
}
void
More information about the wine-patches
mailing list