Cleanup formatting on some files. Remove excessive whitespace.

This commit is contained in:
Christopher Faylor 2000-10-28 05:00:00 +00:00
parent 3c952fed3f
commit eedc36cb12
15 changed files with 753 additions and 675 deletions

View File

@ -1,5 +1,5 @@
dnl Autoconf configure script for Cygwin utilities.
dnl Copyright 1996, 1997 Cygnus Solutions.
dnl Copyright 1996, 1997, 1998, 1999, 2000 Cygnus Solutions.
dnl
dnl This file is part of Cygwin.
dnl

View File

@ -29,8 +29,7 @@ typedef long long longlong;
typedef __int64 longlong;
#endif
const char *known_env_vars[] =
{
const char *known_env_vars[] = {
"c_include_path",
"compiler_path",
"cxx_include_path",
@ -55,21 +54,45 @@ const char *known_env_vars[] =
0
};
struct {
struct
{
const char *name;
int missing_is_good;
} common_apps[] = {
{ "bash", 0 },
{ "cat", 0 },
{ "cpp", 1 },
{ "find", 0 },
{ "gcc", 0 },
{ "gdb", 0 },
{ "ld", 0 },
{ "ls", 0 },
{ "make", 0 },
{ "sh", 0 },
{ 0, 0 }
}
common_apps[] =
{
{
"bash", 0}
,
{
"cat", 0}
,
{
"cpp", 1}
,
{
"find", 0}
,
{
"gcc", 0}
,
{
"gdb", 0}
,
{
"ld", 0}
,
{
"ls", 0}
,
{
"make", 0}
,
{
"sh", 0}
,
{
0, 0}
};
int num_paths = 0, max_paths = 0;
@ -148,7 +171,7 @@ find_on_path (char *file, char *default_extension,
return file;
if (strchr (file, '.'))
default_extension = (char *)"";
default_extension = (char *) "";
for (int i = 0; i < num_paths; i++)
{
@ -263,13 +286,13 @@ struct ExpDirectory
};
struct ImpDirectory
{
{
unsigned characteristics;
unsigned timestamp;
unsigned forwarder_chain;
unsigned name_rva;
unsigned iat_rva;
};
};
void track_down (char *file, char *suffix, int lvl);
@ -339,8 +362,10 @@ dll_info (const char *path, HANDLE fh, int lvl, int recurse)
int nsections = get_word (fh, pe_header_offset + 4 + 2);
char *sections = (char *) malloc (nsections * 40);
SetFilePointer (fh, pe_header_offset + 4 + 20 + get_word (fh, pe_header_offset + 4 + 16),
0, FILE_BEGIN);
SetFilePointer (fh,
pe_header_offset + 4 + 20 + get_word (fh,
pe_header_offset + 4 +
16), 0, FILE_BEGIN);
ReadFile (fh, sections, nsections * 40, &junk, 0);
if (verbose && num_entries >= 1 && export_size > 0)
@ -436,7 +461,8 @@ track_down (char *file, char *suffix, int lvl)
printf ("%s", path);
HANDLE fh = CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
HANDLE fh =
CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (fh == INVALID_HANDLE_VALUE)
{
@ -462,8 +488,7 @@ ls (char *f)
FileTimeToSystemTime (&info.ftLastWriteTime, &systime);
printf ("%5dk %04d/%02d/%02d %s",
(((int) info.nFileSizeLow) + 512) / 1024,
systime.wYear, systime.wMonth, systime.wDay,
f);
systime.wYear, systime.wMonth, systime.wDay, f);
dll_info (f, h, 16, 0);
CloseHandle (h);
@ -498,11 +523,11 @@ cygcheck (char *app)
extern char **environ;
struct RegInfo
{
{
RegInfo *prev;
char *name;
HKEY key;
};
};
void
show_reg (RegInfo * ri, int nest)
@ -538,8 +563,7 @@ scan_registry (RegInfo * prev, HKEY hKey, char *name, int cygnus)
#if 0
char tmp[400];
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError (),
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), tmp,
400, 0);
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), tmp, 400, 0);
printf ("RegQueryInfoKey: %s\n", tmp);
#endif
return;
@ -574,16 +598,6 @@ scan_registry (RegInfo * prev, HKEY hKey, char *name, int cygnus)
break;
}
}
#if 0
else
{
char tmp[400];
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError (),
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), tmp,
400, 0);
printf ("RegEnumValue: %s\n", tmp);
}
#endif
}
free (value_name);
free (value_data);
@ -592,7 +606,8 @@ scan_registry (RegInfo * prev, HKEY hKey, char *name, int cygnus)
char *subkey_name = (char *) malloc (max_subkey_len + 1);
for (i = 0; i < num_subkeys; i++)
{
if (RegEnumKey (hKey, i, subkey_name, max_subkey_len + 1) == ERROR_SUCCESS)
if (RegEnumKey (hKey, i, subkey_name, max_subkey_len + 1) ==
ERROR_SUCCESS)
{
HKEY sKey;
if (RegOpenKeyEx (hKey, subkey_name, 0, KEY_ALL_ACCESS, &sKey)
@ -746,11 +761,12 @@ dump_sysinfo ()
printf ("Listing available drives...\n");
printf ("Drv Type Size Free Flags Name\n");
}
int prev_mode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
int prev_mode =
SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
int drivemask = GetLogicalDrives ();
HINSTANCE k32 = LoadLibrary ("kernel32.dll");
BOOL (WINAPI *gdfse) (LPCSTR, long long *, long long *, long long *) =
BOOL (WINAPI * gdfse) (LPCSTR, long long *, long long *, long long *) =
(BOOL (WINAPI *) (LPCSTR, long long *, long long *, long long *))
GetProcAddress (k32, "GetDiskFreeSpaceExA");
@ -790,8 +806,7 @@ dump_sysinfo ()
int percent_full = -1;
long long free_me = 0ULL, free_bytes = 0ULL, total_bytes = 1ULL;
if (gdfse != NULL
&& gdfse (drive, & free_me, & total_bytes, & free_bytes))
if (gdfse != NULL && gdfse (drive, &free_me, &total_bytes, &free_bytes))
{
capacity_mb = total_bytes / (1024L * 1024L);
percent_full = 100 - (int) ((100.0 * free_me) / total_bytes);
@ -834,7 +849,8 @@ dump_sysinfo ()
{
printf ("fd=floppy, hd=hard drive, cd=CD-ROM, net=Network Share\n");
printf ("CP=Case Preserving, CS=Case Sensitive, UN=Unicode\n");
printf ("PA=Persistent ACLS, FC=File Compression, VC=Volume Compression\n");
printf
("PA=Persistent ACLS, FC=File Compression, VC=Volume Compression\n");
}
printf ("\n");
@ -842,10 +858,9 @@ dump_sysinfo ()
if (givehelp)
{
printf ("Mount entries: these map POSIX directories to your NT drives.\n");
printf ("%-*s %-*s %-*s %s\n",
ml_fsname, "-NT-",
ml_dir, "-POSIX-",
printf
("Mount entries: these map POSIX directories to your NT drives.\n");
printf ("%-*s %-*s %-*s %s\n", ml_fsname, "-NT-", ml_dir, "-POSIX-",
ml_type, "-Type-", "-Flags-");
}
@ -856,16 +871,15 @@ dump_sysinfo ()
{
printf ("%-*s %-*s %-*s %s\n",
ml_fsname, mnt->mnt_fsname,
ml_dir, mnt->mnt_dir,
ml_type, mnt->mnt_type,
mnt->mnt_opts);
ml_dir, mnt->mnt_dir, ml_type, mnt->mnt_type, mnt->mnt_opts);
}
printf ("\n");
add_path ((char *) "\\bin", 4); /* just in case */
if (givehelp)
printf ("Looking to see where common programs can be found, if at all...\n");
printf
("Looking to see where common programs can be found, if at all...\n");
for (i = 0; common_apps[i].name; i++)
if (!find_on_path ((char *) common_apps[i].name, (char *) ".exe", 1, 0))
{
@ -999,26 +1013,30 @@ check_keys ()
CloseHandle (h);
return 0;
}
void
usage ()
{
fprintf (stderr, "Usage: cygcheck [OPTIONS] [program ...]\n");
fprintf (stderr, " -s, --sysinfo = system information (not with -k)\n");
fprintf (stderr, " -v, --verbose = verbose output (indented) (for -s or programs)\n");
fprintf (stderr,
" -v, --verbose = verbose output (indented) (for -s or programs)\n");
fprintf (stderr, " -r, --registry = registry search (requires -s)\n");
fprintf (stderr, " -k, --keycheck = perform a keyboard check session (not with -s)\n");
fprintf (stderr,
" -k, --keycheck = perform a keyboard check session (not with -s)\n");
fprintf (stderr, " -h, --help = give help about the info\n");
fprintf (stderr, "You must at least give either -s or -k or a program name\n");
fprintf (stderr,
"You must at least give either -s or -k or a program name\n");
exit (1);
}
struct option longopts[] = {
{ "sysinfo", no_argument, NULL, 's' },
{ "registry", no_argument, NULL, 'r' },
{ "verbose", no_argument, NULL, 'v' },
{ "keycheck", no_argument, NULL, 'k' },
{ "help", no_argument, NULL, 'h' },
{ 0, no_argument, NULL, 0 }
{"sysinfo", no_argument, NULL, 's'},
{"registry", no_argument, NULL, 'r'},
{"verbose", no_argument, NULL, 'v'},
{"keycheck", no_argument, NULL, 'k'},
{"help", no_argument, NULL, 'h'},
{0, no_argument, NULL, 0}
};
char *opts = "srvkh";
@ -1047,8 +1065,7 @@ main (int argc, char **argv)
break;
default:
usage ();
/*NOTREACHED*/
}
/*NOTREACHED*/}
argc -= optind;
argv += optind;
@ -1059,7 +1076,7 @@ main (int argc, char **argv)
usage ();
if (keycheck)
return check_keys();
return check_keys ();
init_paths ();
@ -1067,12 +1084,14 @@ main (int argc, char **argv)
{
if (argc == 1)
{
printf ("Here is where the OS will find your program, and which dlls\n");
printf
("Here is where the OS will find your program, and which dlls\n");
printf ("will be used for it. Use -v to see DLL version info\n");
}
else
{
printf ("Here is where the OS will find your programs, and which dlls\n");
printf
("Here is where the OS will find your programs, and which dlls\n");
printf ("will be used for them. Use -v to see DLL version info\n");
}

View File

@ -4,11 +4,11 @@
Written by Egor Duda <deo@logos-m.ru>
This file is part of Cygwin.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include <bfd.h>
#include <elf/common.h>
@ -27,35 +27,36 @@ details. */
#define NOTE_NAME_SIZE 16
typedef struct _note_header
{
{
Elf_External_Note elf_note_header;
char name [ NOTE_NAME_SIZE - 1 ]; /* external note contains first byte of data */
}
char name[NOTE_NAME_SIZE - 1]; /* external note contains first byte of data */
}
#ifdef __GNUC__
__attribute__ ((packed))
__attribute__ ((packed))
#endif
note_header ;
note_header;
BOOL verbose = FALSE;
BOOL verbose = FALSE;
int deb_printf ( const char* format, ... )
int deb_printf (const char *format,...)
{
if ( !verbose ) return 0;
if (!verbose)
return 0;
va_list va;
va_start ( va, format );
int ret_val = vprintf ( format, va );
va_end ( va );
va_start (va, format);
int ret_val = vprintf (format, va);
va_end (va);
return ret_val;
}
dumper::dumper ( DWORD pid, DWORD tid, const char* file_name )
dumper::dumper (DWORD pid, DWORD tid, const char *file_name)
{
this->file_name = strdup ( file_name );
this->file_name = strdup (file_name);
this->pid = pid;
this->tid = tid;
core_bfd = NULL;
excl_list = new exclusion ( 20 );
excl_list = new exclusion (20);
list = last = NULL;
@ -63,39 +64,43 @@ dumper::dumper ( DWORD pid, DWORD tid, const char* file_name )
memory_num = module_num = thread_num = 0;
hProcess = OpenProcess ( PROCESS_ALL_ACCESS,
hProcess = OpenProcess (PROCESS_ALL_ACCESS,
FALSE, /* no inheritance */
pid );
if ( !hProcess )
pid);
if (!hProcess)
{
fprintf ( stderr, "Failed to open process #%lu\n", pid );
fprintf (stderr, "Failed to open process #%lu\n", pid);
return;
}
init_core_dump ();
if ( ! sane () ) dumper_abort ();
if (!sane ())
dumper_abort ();
}
dumper::~dumper ()
dumper: :~dumper ()
{
close ();
free ( file_name );
free (file_name);
}
void
dumper::dumper_abort ()
{
close ();
unlink ( file_name );
unlink (file_name);
}
void
dumper::close ()
{
if ( core_bfd ) bfd_close ( core_bfd );
if ( excl_list ) delete excl_list;
if ( hProcess ) CloseHandle ( hProcess );
if (core_bfd)
bfd_close (core_bfd);
if (excl_list)
delete excl_list;
if (hProcess)
CloseHandle (hProcess);
core_bfd = NULL;
hProcess = NULL;
excl_list = NULL;
@ -104,20 +109,23 @@ dumper::close ()
int
dumper::sane ()
{
if ( hProcess == NULL || core_bfd == NULL || excl_list == NULL ) return 0;
if (hProcess == NULL || core_bfd == NULL || excl_list == NULL)
return 0;
return 1;
}
process_entity*
dumper::add_process_entity_to_list ( process_entity_type type )
process_entity *
dumper::add_process_entity_to_list (process_entity_type type)
{
if ( ! sane () ) return NULL;
if (!sane ())
return NULL;
process_entity* new_entity = ( process_entity* ) malloc ( sizeof ( process_entity ) );
if ( new_entity == NULL ) return NULL;
process_entity *new_entity = (process_entity *) malloc (sizeof (process_entity));
if (new_entity == NULL)
return NULL;
new_entity->next = NULL;
new_entity->section = NULL;
if ( last == NULL )
if (last == NULL)
list = new_entity;
else
last->next = new_entity;
@ -126,101 +134,111 @@ dumper::add_process_entity_to_list ( process_entity_type type )
}
int
dumper::add_thread ( DWORD tid, HANDLE hThread )
dumper::add_thread (DWORD tid, HANDLE hThread)
{
if ( ! sane () ) return 0 ;
if (!sane ())
return 0;
CONTEXT* pcontext;
CONTEXT *pcontext;
process_entity* new_entity = add_process_entity_to_list ( pr_ent_thread );
if ( new_entity == NULL ) return 0;
process_entity *new_entity = add_process_entity_to_list (pr_ent_thread);
if (new_entity == NULL)
return 0;
new_entity->type = pr_ent_thread;
thread_num++;
new_entity->u.thread.tid = tid;
new_entity->u.thread.hThread = hThread;
pcontext = &( new_entity->u.thread.context );
pcontext = &(new_entity->u.thread.context);
pcontext->ContextFlags = CONTEXT_FULL | CONTEXT_FLOATING_POINT;
if ( ! GetThreadContext ( hThread, pcontext ) ) return 0;
if (!GetThreadContext (hThread, pcontext))
return 0;
deb_printf ( "added thread %u\n", tid );
deb_printf ("added thread %u\n", tid);
return 1;
}
int
dumper::add_mem_region ( LPBYTE base, DWORD size )
dumper::add_mem_region (LPBYTE base, DWORD size)
{
if ( ! sane () ) return 0;
if (!sane ())
return 0;
if ( base == NULL || size == 0 ) return 1; // just ignore empty regions
if (base == NULL || size == 0)
return 1; // just ignore empty regions
process_entity* new_entity = add_process_entity_to_list ( pr_ent_memory );
if ( new_entity == NULL ) return 0;
process_entity *new_entity = add_process_entity_to_list (pr_ent_memory);
if (new_entity == NULL)
return 0;
new_entity->type = pr_ent_memory;
memory_num++;
new_entity->u.memory.base = base;
new_entity->u.memory.size = size;
deb_printf ( "added memory region %08x-%08x\n", (DWORD)base, (DWORD)base + size );
deb_printf ("added memory region %08x-%08x\n", (DWORD) base, (DWORD) base + size);
return 1;
}
/*
* split_add_mem_region scans list of regions to be excluded from dumping process
* (excl_list) and removes all "excluded" parts from given region
*/
/* split_add_mem_region scans list of regions to be excluded from dumping process
(excl_list) and removes all "excluded" parts from given region. */
int
dumper::split_add_mem_region ( LPBYTE base, DWORD size )
dumper::split_add_mem_region (LPBYTE base, DWORD size)
{
if ( ! sane () ) return 0;
if (!sane ())
return 0;
if ( base == NULL || size == 0 ) return 1; // just ignore empty regions
if (base == NULL || size == 0)
return 1; // just ignore empty regions
LPBYTE last_base = base;
for ( process_mem_region* p = excl_list->region;
for (process_mem_region * p = excl_list->region;
p < excl_list->region + excl_list->last;
p++ )
p++)
{
if ( p->base >= base + size || p->base + p->size <= base ) continue;
if (p->base >= base + size || p->base + p->size <= base)
continue;
if ( p->base <= base )
if (p->base <= base)
{
last_base = p->base + p->size;
continue ;
continue;
}
add_mem_region ( last_base, p->base - last_base );
add_mem_region (last_base, p->base - last_base);
last_base = p->base + p->size;
}
if ( last_base < base + size )
add_mem_region ( last_base, base + size - last_base );
if (last_base < base + size)
add_mem_region (last_base, base + size - last_base);
return 1;
}
int
dumper::add_module ( LPVOID base_address )
dumper::add_module (LPVOID base_address)
{
if ( ! sane () ) return 0;
if (!sane ())
return 0;
char* module_name = psapi_get_module_name ( hProcess, (DWORD) base_address );
if ( module_name == NULL ) return 1;
char *module_name = psapi_get_module_name (hProcess, (DWORD) base_address);
if (module_name == NULL)
return 1;
process_entity* new_entity = add_process_entity_to_list ( pr_ent_module );
if ( new_entity == NULL ) return 0;
process_entity *new_entity = add_process_entity_to_list (pr_ent_module);
if (new_entity == NULL)
return 0;
new_entity->type = pr_ent_module;
module_num++;
new_entity->u.module.base_address = base_address;
new_entity->u.module.name = module_name;
parse_pe ( module_name, excl_list );
parse_pe (module_name, excl_list);
deb_printf ( "added module %08x %s\n", base_address, module_name );
deb_printf ("added module %08x %s\n", base_address, module_name);
return 1;
}
@ -229,73 +247,77 @@ dumper::add_module ( LPVOID base_address )
int
dumper::collect_memory_sections ()
{
if ( ! sane () ) return 0;
if (!sane ())
return 0;
LPBYTE current_page_address;
LPBYTE last_base = (LPBYTE) 0xFFFFFFFF;
DWORD last_size = 0;
DWORD done;
char mem_buf [ PAGE_BUFFER_SIZE ];
char mem_buf[PAGE_BUFFER_SIZE];
MEMORY_BASIC_INFORMATION mbi;
if ( hProcess == NULL ) return 0;
if (hProcess == NULL)
return 0;
for ( current_page_address = 0; current_page_address < (LPBYTE) 0xFFFF0000; )
for (current_page_address = 0; current_page_address < (LPBYTE) 0xFFFF0000;)
{
if ( ! VirtualQueryEx ( hProcess, current_page_address, &mbi, sizeof ( mbi ) ) )
break ;
if (!VirtualQueryEx (hProcess, current_page_address, &mbi, sizeof (mbi)))
break;
int skip_region_p = 0;
if ( mbi.Protect & ( PAGE_NOACCESS | PAGE_GUARD ) ||
mbi.State != MEM_COMMIT ) skip_region_p = 1;
if (mbi.Protect & (PAGE_NOACCESS | PAGE_GUARD) ||
mbi.State != MEM_COMMIT)
skip_region_p = 1;
if ( ! skip_region_p )
if (!skip_region_p)
{
/* just to make sure that later we'll be able to read it.
According to MS docs either region is all-readable or
all-nonreadable */
if ( ! ReadProcessMemory ( hProcess, current_page_address, mem_buf, sizeof ( mem_buf ), &done ) )
if (!ReadProcessMemory (hProcess, current_page_address, mem_buf, sizeof (mem_buf), &done))
{
const char* pt[10] ;
pt[0] = ( mbi.Protect & PAGE_READONLY ) ? "RO " : "";
pt[1] = ( mbi.Protect & PAGE_READWRITE ) ? "RW " : "";
pt[2] = ( mbi.Protect & PAGE_WRITECOPY ) ? "WC " : "";
pt[3] = ( mbi.Protect & PAGE_EXECUTE ) ? "EX " : "";
pt[4] = ( mbi.Protect & PAGE_EXECUTE_READ ) ? "EXRO " : "";
pt[5] = ( mbi.Protect & PAGE_EXECUTE_READWRITE ) ? "EXRW " : "";
pt[6] = ( mbi.Protect & PAGE_EXECUTE_WRITECOPY ) ? "EXWC " : "";
pt[7] = ( mbi.Protect & PAGE_GUARD ) ? "GRD " : "";
pt[8] = ( mbi.Protect & PAGE_NOACCESS ) ? "NA " : "";
pt[9] = ( mbi.Protect & PAGE_NOCACHE ) ? "NC " : "";
char buf [ 10*6 ] ;
buf [ 0 ] = '\0';
for ( int i = 0 ; i < 10 ; i++ ) strcat ( buf, pt[i] );
const char *pt[10];
pt[0] = (mbi.Protect & PAGE_READONLY) ? "RO " : "";
pt[1] = (mbi.Protect & PAGE_READWRITE) ? "RW " : "";
pt[2] = (mbi.Protect & PAGE_WRITECOPY) ? "WC " : "";
pt[3] = (mbi.Protect & PAGE_EXECUTE) ? "EX " : "";
pt[4] = (mbi.Protect & PAGE_EXECUTE_READ) ? "EXRO " : "";
pt[5] = (mbi.Protect & PAGE_EXECUTE_READWRITE) ? "EXRW " : "";
pt[6] = (mbi.Protect & PAGE_EXECUTE_WRITECOPY) ? "EXWC " : "";
pt[7] = (mbi.Protect & PAGE_GUARD) ? "GRD " : "";
pt[8] = (mbi.Protect & PAGE_NOACCESS) ? "NA " : "";
pt[9] = (mbi.Protect & PAGE_NOCACHE) ? "NC " : "";
char buf[10 * 6];
buf[0] = '\0';
for (int i = 0; i < 10; i++)
strcat (buf, pt[i]);
deb_printf ( "warning: failed to read memory at %08x-%08x. protect = %s\n",
(DWORD)current_page_address,
(DWORD)current_page_address + mbi.RegionSize,
buf );
deb_printf ("warning: failed to read memory at %08x-%08x. protect = %s\n",
(DWORD) current_page_address,
(DWORD) current_page_address + mbi.RegionSize,
buf);
skip_region_p = 1;
}
}
if ( ! skip_region_p )
if (!skip_region_p)
{
if ( last_base + last_size == current_page_address )
if (last_base + last_size == current_page_address)
last_size += mbi.RegionSize;
else
{
split_add_mem_region ( last_base, last_size );
split_add_mem_region (last_base, last_size);
last_base = (LPBYTE) mbi.BaseAddress;
last_size = mbi.RegionSize;
}
}
else
{
split_add_mem_region ( last_base, last_size );
split_add_mem_region (last_base, last_size);
last_base = NULL;
last_size = 0;
}
@ -304,14 +326,15 @@ dumper::collect_memory_sections ()
}
/* dump last sections, if any */
split_add_mem_region ( last_base, last_size );
split_add_mem_region (last_base, last_size);
return 1;
};
int
dumper::dump_memory_region ( asection* to, process_mem_region* memory )
dumper::dump_memory_region (asection * to, process_mem_region * memory)
{
if ( ! sane () ) return 0;
if (!sane ())
return 0;
DWORD size = memory->size;
DWORD todo;
@ -319,126 +342,132 @@ dumper::dump_memory_region ( asection* to, process_mem_region* memory )
LPBYTE pos = memory->base;
DWORD sect_pos = 0;
if ( to == NULL || memory == NULL ) return 0;
if (to == NULL || memory == NULL)
return 0;
char mem_buf [ PAGE_BUFFER_SIZE ];
char mem_buf[PAGE_BUFFER_SIZE];
while ( size > 0 )
while (size > 0)
{
todo = min ( size, PAGE_BUFFER_SIZE );
if ( ! ReadProcessMemory ( hProcess, pos, mem_buf, todo, &done ) )
todo = min (size, PAGE_BUFFER_SIZE);
if (!ReadProcessMemory (hProcess, pos, mem_buf, todo, &done))
{
deb_printf ( "Error reading process memory at %x(%x) %u\n", pos, todo, GetLastError () );
deb_printf ("Error reading process memory at %x(%x) %u\n", pos, todo, GetLastError ());
return 0;
}
size -= done;
pos += done;
if ( ! bfd_set_section_contents ( core_bfd, to, mem_buf, sect_pos, done ) )
if (!bfd_set_section_contents (core_bfd, to, mem_buf, sect_pos, done))
{
bfd_perror ( "writing memory region to bfd" );
bfd_perror ("writing memory region to bfd");
dumper_abort ();
return 0;
} ;
};
sect_pos += done;
}
return 1;
}
int
dumper::dump_thread ( asection* to, process_thread* thread )
dumper::dump_thread (asection * to, process_thread * thread)
{
if ( ! sane () ) return 0;
if (!sane ())
return 0;
if ( to == NULL || thread == NULL ) return 0;
if (to == NULL || thread == NULL)
return 0;
win32_pstatus thread_pstatus;
note_header header;
bfd_putl32 ( NOTE_NAME_SIZE, header.elf_note_header.namesz );
bfd_putl32 ( sizeof ( thread_pstatus ), header.elf_note_header.descsz );
bfd_putl32 ( NT_WIN32PSTATUS, header.elf_note_header.type );
strncpy ( (char*) & header.elf_note_header.name, "win32thread", NOTE_NAME_SIZE );
bfd_putl32 (NOTE_NAME_SIZE, header.elf_note_header.namesz);
bfd_putl32 (sizeof (thread_pstatus), header.elf_note_header.descsz);
bfd_putl32 (NT_WIN32PSTATUS, header.elf_note_header.type);
strncpy ((char *) &header.elf_note_header.name, "win32thread", NOTE_NAME_SIZE);
thread_pstatus.data_type = NOTE_INFO_THREAD;
thread_pstatus.data.thread_info.tid = thread->tid;
if ( tid == 0 )
if (tid == 0)
{
/* this is a special case. we don't know, which thread
was active when exception occured, so let's blame
the first one */
thread_pstatus.data.thread_info.is_active_thread = TRUE ;
tid = (DWORD) -1 ;
thread_pstatus.data.thread_info.is_active_thread = TRUE;
tid = (DWORD) - 1;
}
else if ( tid > 0 && thread->tid == tid )
else if (tid > 0 && thread->tid == tid)
thread_pstatus.data.thread_info.is_active_thread = TRUE;
else
thread_pstatus.data.thread_info.is_active_thread = FALSE;
memcpy ( &(thread_pstatus.data.thread_info.thread_context),
memcpy (&(thread_pstatus.data.thread_info.thread_context),
&(thread->context),
sizeof ( thread->context ) );
sizeof (thread->context));
if ( ! bfd_set_section_contents ( core_bfd, to, &header,
if (!bfd_set_section_contents (core_bfd, to, &header,
0,
sizeof ( header ) ) ||
! bfd_set_section_contents ( core_bfd, to, &thread_pstatus,
sizeof ( header ),
sizeof ( thread_pstatus ) ) )
sizeof (header)) ||
!bfd_set_section_contents (core_bfd, to, &thread_pstatus,
sizeof (header),
sizeof (thread_pstatus)))
{
bfd_perror ( "writing thread info to bfd" );
bfd_perror ("writing thread info to bfd");
dumper_abort ();
return 0;
} ;
};
return 1;
}
int
dumper::dump_module ( asection* to, process_module* module )
dumper::dump_module (asection * to, process_module * module)
{
if ( ! sane () ) return 0;
if (!sane ())
return 0;
if ( to == NULL || module == NULL ) return 0;
if (to == NULL || module == NULL)
return 0;
struct win32_pstatus* module_pstatus_ptr;
struct win32_pstatus *module_pstatus_ptr;
int note_length = sizeof ( struct win32_pstatus ) + strlen ( module->name );
int note_length = sizeof (struct win32_pstatus) + strlen (module->name);
char* buf = (char*) malloc ( note_length );
char *buf = (char *) malloc (note_length);
if ( ! buf )
if (!buf)
{
fprintf ( stderr, "Error alloating memory. Dumping aborted.\n" );
fprintf (stderr, "Error alloating memory. Dumping aborted.\n");
goto out;
} ;
};
module_pstatus_ptr = (struct win32_pstatus*) buf;
module_pstatus_ptr = (struct win32_pstatus *) buf;
note_header header;
bfd_putl32 ( NOTE_NAME_SIZE, header.elf_note_header.namesz );
bfd_putl32 ( note_length, header.elf_note_header.descsz );
bfd_putl32 ( NT_WIN32PSTATUS, header.elf_note_header.type );
strncpy ( (char*) & header.elf_note_header.name, "win32module", NOTE_NAME_SIZE );
bfd_putl32 (NOTE_NAME_SIZE, header.elf_note_header.namesz);
bfd_putl32 (note_length, header.elf_note_header.descsz);
bfd_putl32 (NT_WIN32PSTATUS, header.elf_note_header.type);
strncpy ((char *) &header.elf_note_header.name, "win32module", NOTE_NAME_SIZE);
module_pstatus_ptr->data_type = NOTE_INFO_MODULE;
module_pstatus_ptr->data.module_info.base_address = module->base_address;
module_pstatus_ptr->data.module_info.module_name_size = strlen ( module->name ) + 1;
strcpy ( module_pstatus_ptr->data.module_info.module_name, module->name );
module_pstatus_ptr->data.module_info.module_name_size = strlen (module->name) + 1;
strcpy (module_pstatus_ptr->data.module_info.module_name, module->name);
if ( ! bfd_set_section_contents ( core_bfd, to, &header,
if (!bfd_set_section_contents (core_bfd, to, &header,
0,
sizeof ( header ) ) ||
! bfd_set_section_contents ( core_bfd, to, module_pstatus_ptr,
sizeof ( header ),
note_length ) )
sizeof (header)) ||
!bfd_set_section_contents (core_bfd, to, module_pstatus_ptr,
sizeof (header),
note_length))
{
bfd_perror ( "writing module info to bfd" );
bfd_perror ("writing module info to bfd");
goto out;
};
return 1;
out:
if ( buf ) free ( buf );
if (buf)
free (buf);
dumper_abort ();
return 0;
@ -447,49 +476,51 @@ out:
int
dumper::collect_process_information ()
{
if ( ! sane () ) return 0;
if (!sane ())
return 0;
if ( ! DebugActiveProcess ( pid ) )
if (!DebugActiveProcess (pid))
{
fprintf ( stderr, "Cannot attach to process #%lu", pid );
fprintf (stderr, "Cannot attach to process #%lu", pid);
return 0;
}
char event_name [ sizeof ( "cygwin_error_start_event" ) + 20 ];
sprintf ( event_name, "cygwin_error_start_event%16lx", pid );
HANDLE sync_with_debugee = OpenEvent ( EVENT_MODIFY_STATE, FALSE, event_name );
char event_name[sizeof ("cygwin_error_start_event") + 20];
sprintf (event_name, "cygwin_error_start_event%16lx", pid);
HANDLE sync_with_debugee = OpenEvent (EVENT_MODIFY_STATE, FALSE, event_name);
DEBUG_EVENT current_event;
while (1)
{
if ( ! WaitForDebugEvent ( &current_event, 20000 ) ) return 0;
if (!WaitForDebugEvent (&current_event, 20000))
return 0;
switch (current_event.dwDebugEventCode)
{
case CREATE_THREAD_DEBUG_EVENT:
if ( ! add_thread ( current_event.dwThreadId,
current_event.u.CreateThread.hThread ) )
if (!add_thread (current_event.dwThreadId,
current_event.u.CreateThread.hThread))
goto failed;
break;
case CREATE_PROCESS_DEBUG_EVENT:
if ( ! add_module ( current_event.u.CreateProcessInfo.lpBaseOfImage ) ||
! add_thread ( current_event.dwThreadId,
current_event.u.CreateProcessInfo.hThread ) )
if (!add_module (current_event.u.CreateProcessInfo.lpBaseOfImage) ||
!add_thread (current_event.dwThreadId,
current_event.u.CreateProcessInfo.hThread))
goto failed;
break;
case EXIT_PROCESS_DEBUG_EVENT:
deb_printf ( "debugee quits" );
ContinueDebugEvent ( current_event.dwProcessId,
deb_printf ("debugee quits");
ContinueDebugEvent (current_event.dwProcessId,
current_event.dwThreadId,
DBG_CONTINUE );
DBG_CONTINUE);
return 1;
@ -497,7 +528,7 @@ dumper::collect_process_information ()
case LOAD_DLL_DEBUG_EVENT:
if ( ! add_module ( current_event.u.LoadDll.lpBaseOfDll ) )
if (!add_module (current_event.u.LoadDll.lpBaseOfDll))
goto failed;
break;
@ -508,20 +539,21 @@ dumper::collect_process_information ()
/* got all info. time to dump */
if ( ! prepare_core_dump () )
if (!prepare_core_dump ())
{
fprintf ( stderr, "Failed to prepare core dump\n" );
fprintf (stderr, "Failed to prepare core dump\n");
goto failed;
};
if ( ! write_core_dump () )
if (!write_core_dump ())
{
fprintf ( stderr, "Failed to write core dump\n" );
fprintf (stderr, "Failed to write core dump\n");
goto failed;
};
/* signal a debugee that we've finished */
if ( sync_with_debugee ) SetEvent ( sync_with_debugee );
if (sync_with_debugee)
SetEvent (sync_with_debugee);
break;
@ -531,13 +563,14 @@ dumper::collect_process_information ()
}
ContinueDebugEvent ( current_event.dwProcessId,
ContinueDebugEvent (current_event.dwProcessId,
current_event.dwThreadId,
DBG_CONTINUE );
DBG_CONTINUE);
}
failed:
/* set debugee free */
if ( sync_with_debugee ) SetEvent ( sync_with_debugee );
if (sync_with_debugee)
SetEvent (sync_with_debugee);
return 0;
}
@ -547,16 +580,16 @@ dumper::init_core_dump ()
{
bfd_init ();
core_bfd = bfd_openw ( file_name, "elf32-i386" );
if ( core_bfd == NULL )
core_bfd = bfd_openw (file_name, "elf32-i386");
if (core_bfd == NULL)
{
bfd_perror ( "opening bfd" );
bfd_perror ("opening bfd");
goto failed;
}
if ( ! bfd_set_format ( core_bfd, bfd_core ) )
if (!bfd_set_format (core_bfd, bfd_core))
{
bfd_perror ( "setting bfd format" );
bfd_perror ("setting bfd format");
goto failed;
}
@ -571,43 +604,44 @@ failed:
int
dumper::prepare_core_dump ()
{
if ( ! sane () ) return 0;
if (!sane ())
return 0;
int sect_no = 0;
char sect_name [ 50 ];
char sect_name[50];
flagword sect_flags;
DWORD sect_size;
bfd_vma sect_vma;
asection* new_section;
asection *new_section;
for ( process_entity* p = list; p != NULL; p = p->next )
for (process_entity * p = list; p != NULL; p = p->next)
{
sect_no++;
switch ( p->type )
switch (p->type)
{
case pr_ent_memory:
sprintf ( sect_name, ".mem/%u", sect_no );
sprintf (sect_name, ".mem/%u", sect_no);
sect_flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD;
sect_size = p->u.memory.size;
sect_vma = (bfd_vma)(p->u.memory.base);
sect_vma = (bfd_vma) (p->u.memory.base);
break;
case pr_ent_thread:
sprintf ( sect_name, ".note/%u", sect_no );
sprintf (sect_name, ".note/%u", sect_no);
sect_flags = SEC_HAS_CONTENTS | SEC_LOAD;
sect_size = sizeof ( note_header ) + sizeof ( struct win32_pstatus );
sect_size = sizeof (note_header) + sizeof (struct win32_pstatus);
sect_vma = 0;
break;
case pr_ent_module:
sprintf ( sect_name, ".note/%u", sect_no );
sprintf (sect_name, ".note/%u", sect_no);
sect_flags = SEC_HAS_CONTENTS | SEC_LOAD;
sect_size = sizeof ( note_header ) + sizeof ( struct win32_pstatus ) +
(bfd_size_type)( strlen (p->u.module.name) );
sect_size = sizeof (note_header) + sizeof (struct win32_pstatus) +
(bfd_size_type) (strlen (p->u.module.name));
sect_vma = 0;
break;
@ -615,29 +649,29 @@ dumper::prepare_core_dump ()
continue;
}
if ( p->type == pr_ent_module && status_section != NULL )
if (p->type == pr_ent_module && status_section != NULL)
{
if ( ! bfd_set_section_size ( core_bfd,
if (!bfd_set_section_size (core_bfd,
status_section,
status_section->_raw_size + sect_size ) )
status_section->_raw_size + sect_size))
{
bfd_perror ( "resizing status section" );
bfd_perror ("resizing status section");
goto failed;
};
continue;
}
deb_printf ( "creating section (type%u) %s(%u), flags=%08x\n",
p->type, sect_name, sect_size, sect_flags );
deb_printf ("creating section (type%u) %s(%u), flags=%08x\n",
p->type, sect_name, sect_size, sect_flags);
char* buf = strdup ( sect_name );
new_section = bfd_make_section ( core_bfd, buf );
char *buf = strdup (sect_name);
new_section = bfd_make_section (core_bfd, buf);
if ( new_section == NULL ||
! bfd_set_section_flags ( core_bfd, new_section, sect_flags ) ||
! bfd_set_section_size ( core_bfd, new_section, sect_size ) )
if (new_section == NULL ||
!bfd_set_section_flags (core_bfd, new_section, sect_flags) ||
!bfd_set_section_size (core_bfd, new_section, sect_size))
{
bfd_perror ( "creating section" );
bfd_perror ("creating section");
goto failed;
};
@ -657,30 +691,32 @@ failed:
int
dumper::write_core_dump ()
{
if ( ! sane () ) return 0;
if (!sane ())
return 0;
for ( process_entity* p = list; p != NULL; p = p->next )
for (process_entity * p = list; p != NULL; p = p->next)
{
if ( p->section == NULL ) continue;
if (p->section == NULL)
continue;
deb_printf ( "writing section type=%u base=%08x size=%08x flags=%08x\n",
deb_printf ("writing section type=%u base=%08x size=%08x flags=%08x\n",
p->type,
p->section->vma,
p->section->_raw_size,
p->section->flags );
p->section->flags);
switch ( p->type )
switch (p->type)
{
case pr_ent_memory:
dump_memory_region ( p->section, &(p->u.memory) );
dump_memory_region (p->section, &(p->u.memory));
break;
case pr_ent_thread:
dump_thread ( p->section, &(p->u.thread) );
dump_thread (p->section, &(p->u.thread));
break;
case pr_ent_module:
dump_module ( p->section, &(p->u.module) );
dump_module (p->section, &(p->u.module));
break;
default:
@ -694,17 +730,17 @@ dumper::write_core_dump ()
static void
usage ()
{
fprintf ( stderr, "Usage: dumper [-v] [-c filename] pid\n" );
fprintf ( stderr, "-c filename -- dump core to filename.core\n" );
fprintf ( stderr, "-d -- print some debugging info while dumping\n" );
fprintf ( stderr, "pid -- win32-pid of process to dump\n" );
fprintf (stderr, "Usage: dumper [-v] [-c filename] pid\n");
fprintf (stderr, "-c filename -- dump core to filename.core\n");
fprintf (stderr, "-d -- print some debugging info while dumping\n");
fprintf (stderr, "pid -- win32-pid of process to dump\n");
}
int
main( int argc, char** argv )
main (int argc, char **argv)
{
int opt;
char* p = "";
char *p = "";
DWORD pid;
while ((opt = getopt (argc, argv, "dc:")) != EOF)
@ -714,25 +750,25 @@ main( int argc, char** argv )
verbose = TRUE;
break;
case 'c':
char win32_name [ MAX_PATH ];
cygwin_conv_to_win32_path ( optarg, win32_name );
if ( ( p = strrchr ( win32_name, '\\' ) ) )
char win32_name[MAX_PATH];
cygwin_conv_to_win32_path (optarg, win32_name);
if ((p = strrchr (win32_name, '\\')))
p++;
else
p = win32_name;
break;
}
char* core_file = (char*) malloc ( strlen ( p ) + sizeof ( ".core" ) );
if ( ! core_file )
char *core_file = (char *) malloc (strlen (p) + sizeof (".core"));
if (!core_file)
{
fprintf ( stderr, "error allocating memory\n" );
fprintf (stderr, "error allocating memory\n");
return -1;
}
sprintf ( core_file, "%s.core", p );
sprintf (core_file, "%s.core", p);
if ( argv && *(argv+optind) )
pid = atoi ( *(argv+optind) );
if (argv && *(argv + optind))
pid = atoi (*(argv + optind));
else
{
usage ();
@ -741,14 +777,14 @@ main( int argc, char** argv )
DWORD tid = 0;
if ( verbose )
printf ( "dumping process #%lu to %s\n", pid, core_file );
if (verbose)
printf ("dumping process #%lu to %s\n", pid, core_file);
dumper d ( pid, tid, core_file );
if ( ! d.sane () )
dumper d (pid, tid, core_file);
if (!d.sane ())
return -1;
d.collect_process_information ();
free ( core_file );
free (core_file);
return 0;
};

View File

@ -8,7 +8,8 @@
#include <sys/acl.h>
#include <sys/stat.h>
char *permstr (mode_t perm)
char *
permstr (mode_t perm)
{
static char pbuf[4];
@ -20,7 +21,8 @@ char *permstr (mode_t perm)
}
#if 0
char *username (uid_t uid)
char *
username (uid_t uid)
{
static char ubuf[256];
struct passwd *pw;
@ -31,7 +33,8 @@ char *username (uid_t uid)
strcpy (ubuf, "<unknown>");
}
char *groupname (gid_t gid)
char *
groupname (gid_t gid)
{
static char gbuf[256];
struct group *gr;
@ -74,7 +77,7 @@ main (int argc, char **argv)
perror (argv[0]);
continue;
}
if (! first)
if (!first)
putchar ('\n');
first = 0;
printf ("# file: %s\n", argv[c]);
@ -121,4 +124,3 @@ main (int argc, char **argv)
}
return 0;
}

View File

@ -17,93 +17,95 @@ details. */
static int psapi_loaded = 0;
static HMODULE psapi_module_handle = NULL;
typedef BOOL WINAPI (tf_EnumProcessModules ) ( HANDLE, HMODULE*, DWORD, LPDWORD );
typedef BOOL WINAPI (tf_GetModuleInformation) ( HANDLE, HMODULE, LPMODULEINFO, DWORD );
typedef DWORD WINAPI (tf_GetModuleFileNameExA) ( HANDLE, HMODULE, LPSTR, DWORD );
typedef BOOL WINAPI (tf_EnumProcessModules) (HANDLE, HMODULE *, DWORD,
LPDWORD);
typedef BOOL WINAPI (tf_GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO,
DWORD);
typedef DWORD WINAPI (tf_GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR,
DWORD);
static tf_EnumProcessModules *psapi_EnumProcessModules = NULL;
static tf_GetModuleInformation *psapi_GetModuleInformation = NULL;
static tf_GetModuleFileNameExA *psapi_GetModuleFileNameExA = NULL;
/*
* Returns full name of Dll, which is loaded by hProcess at BaseAddress
* Uses psapi.dll
*/
/* Returns full name of Dll, which is loaded by hProcess at BaseAddress.
Uses psapi.dll. */
char*
psapi_get_module_name ( HANDLE hProcess, DWORD BaseAddress )
char *
psapi_get_module_name (HANDLE hProcess, DWORD BaseAddress)
{
DWORD len;
MODULEINFO mi;
unsigned int i;
HMODULE dh_buf [ 1 ];
HMODULE* DllHandle = dh_buf;
HMODULE dh_buf[1];
HMODULE *DllHandle = dh_buf;
DWORD cbNeeded;
BOOL ok;
char name_buf [ MAX_PATH + 1 ];
char name_buf[MAX_PATH + 1];
if ( !psapi_loaded ||
if (!psapi_loaded ||
psapi_EnumProcessModules == NULL ||
psapi_GetModuleInformation == NULL ||
psapi_GetModuleFileNameExA == NULL )
psapi_GetModuleFileNameExA == NULL)
{
if ( psapi_loaded ) goto failed;
if (psapi_loaded)
goto failed;
psapi_loaded = 1;
psapi_module_handle = LoadLibrary ( "psapi.dll" );
if ( ! psapi_module_handle )
psapi_module_handle = LoadLibrary ("psapi.dll");
if (!psapi_module_handle)
goto failed;
psapi_EnumProcessModules = (tf_EnumProcessModules *) GetProcAddress ( psapi_module_handle, "EnumProcessModules" );
psapi_GetModuleInformation = (tf_GetModuleInformation *) GetProcAddress ( psapi_module_handle, "GetModuleInformation" );
psapi_GetModuleFileNameExA = (tf_GetModuleFileNameExA*) GetProcAddress ( psapi_module_handle, "GetModuleFileNameExA" );
if ( psapi_EnumProcessModules == NULL ||
psapi_GetModuleInformation == NULL ||
psapi_GetModuleFileNameExA == NULL ) goto failed;
}
ok = (*psapi_EnumProcessModules) ( hProcess,
DllHandle,
sizeof ( HMODULE ),
&cbNeeded );
if ( !ok || !cbNeeded ) goto failed;
DllHandle = (HMODULE*) malloc ( cbNeeded );
if ( ! DllHandle ) goto failed;
ok = (*psapi_EnumProcessModules) ( hProcess,
DllHandle,
cbNeeded,
&cbNeeded );
if ( ! ok )
{
free ( DllHandle );
psapi_EnumProcessModules =
(tf_EnumProcessModules *) GetProcAddress (psapi_module_handle,
"EnumProcessModules");
psapi_GetModuleInformation =
(tf_GetModuleInformation *) GetProcAddress (psapi_module_handle,
"GetModuleInformation");
psapi_GetModuleFileNameExA =
(tf_GetModuleFileNameExA *) GetProcAddress (psapi_module_handle,
"GetModuleFileNameExA");
if (psapi_EnumProcessModules == NULL
|| psapi_GetModuleInformation == NULL
|| psapi_GetModuleFileNameExA == NULL)
goto failed;
}
for ( i = 0; i < cbNeeded / sizeof ( HMODULE ); i++ )
ok = (*psapi_EnumProcessModules) (hProcess,
DllHandle, sizeof (HMODULE), &cbNeeded);
if (!ok || !cbNeeded)
goto failed;
DllHandle = (HMODULE *) malloc (cbNeeded);
if (!DllHandle)
goto failed;
ok = (*psapi_EnumProcessModules) (hProcess, DllHandle, cbNeeded, &cbNeeded);
if (!ok)
{
if ( ! (*psapi_GetModuleInformation) ( hProcess,
DllHandle [ i ],
&mi,
sizeof ( mi ) ) )
{
free ( DllHandle );
free (DllHandle);
goto failed;
}
len = (*psapi_GetModuleFileNameExA) ( hProcess,
DllHandle [ i ],
name_buf,
MAX_PATH );
if ( len == 0 )
for (i = 0; i < cbNeeded / sizeof (HMODULE); i++)
{
free ( DllHandle );
if (!(*psapi_GetModuleInformation) (hProcess,
DllHandle[i], &mi, sizeof (mi)))
{
free (DllHandle);
goto failed;
}
if ( (DWORD) (mi.lpBaseOfDll) == BaseAddress )
len = (*psapi_GetModuleFileNameExA) (hProcess,
DllHandle[i], name_buf, MAX_PATH);
if (len == 0)
{
free ( DllHandle );
return strdup ( name_buf );
free (DllHandle);
goto failed;
}
if ((DWORD) (mi.lpBaseOfDll) == BaseAddress)
{
free (DllHandle);
return strdup (name_buf);
}
}

View File

@ -4,11 +4,11 @@
Written by Egor Duda <deo@logos-m.ru>
This file is part of Cygwin.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include <bfd.h>
#include <stdio.h>
@ -17,22 +17,25 @@ details. */
#include "dumper.h"
int
exclusion::add ( LPBYTE mem_base, DWORD mem_size )
exclusion::add (LPBYTE mem_base, DWORD mem_size)
{
while ( last >= size ) size += step;
region = (process_mem_region*) realloc ( region, size * sizeof ( process_mem_region ) );
if ( region == NULL ) return 0;
region [ last ].base = mem_base;
region [ last ].size = mem_size;
while (last >= size)
size += step;
region = (process_mem_region *) realloc (region, size * sizeof (process_mem_region));
if (region == NULL)
return 0;
region[last].base = mem_base;
region[last].size = mem_size;
last++;
return 1;
};
int cmp_regions ( const void* r1, const void* r2 )
int
cmp_regions (const void *r1, const void *r2)
{
if ( ((process_mem_region*) r1)->base < ((process_mem_region*) r2)->base )
if (((process_mem_region *) r1)->base < ((process_mem_region *) r2)->base)
return -1;
if ( ((process_mem_region*) r1)->base > ((process_mem_region*) r2)->base )
if (((process_mem_region *) r1)->base > ((process_mem_region *) r2)->base)
return 1;
return 0;
}
@ -40,13 +43,13 @@ int cmp_regions ( const void* r1, const void* r2 )
int
exclusion::sort_and_check ()
{
qsort ( region, last, sizeof ( process_mem_region ), &cmp_regions );
for ( process_mem_region* p = region; p < region + last - 1; p++ )
qsort (region, last, sizeof (process_mem_region), &cmp_regions);
for (process_mem_region * p = region; p < region + last - 1; p++)
{
process_mem_region* q = p + 1;
if ( p->base + size > q->base )
process_mem_region *q = p + 1;
if (p->base + size > q->base)
{
fprintf ( stderr, "region error @ %08x", p->base );
fprintf (stderr, "region error @ %08x", p->base);
return 0;
}
}
@ -54,35 +57,35 @@ exclusion::sort_and_check ()
}
static void
select_data_section ( bfd *abfd, asection *sect, PTR obj )
select_data_section (bfd * abfd, asection * sect, PTR obj)
{
exclusion* excl_list = (exclusion*) obj;
exclusion *excl_list = (exclusion *) obj;
if ( ( sect->flags & ( SEC_CODE | SEC_DEBUGGING ) ) &&
sect->vma && sect->_raw_size )
if ((sect->flags & (SEC_CODE | SEC_DEBUGGING)) &&
sect->vma && sect->_raw_size)
{
excl_list->add ( (LPBYTE)sect->vma, (DWORD)sect->_raw_size );
deb_printf ( "excluding section: %20s %08lx\n", sect->name, sect->_raw_size);
excl_list->add ((LPBYTE) sect->vma, (DWORD) sect->_raw_size);
deb_printf ("excluding section: %20s %08lx\n", sect->name, sect->_raw_size);
}
}
int
parse_pe ( const char* file_name, exclusion* excl_list )
parse_pe (const char *file_name, exclusion * excl_list)
{
if ( file_name == NULL || excl_list == NULL ) return 0;
if (file_name == NULL || excl_list == NULL)
return 0;
bfd* abfd = bfd_openr ( file_name, "pei-i386" );
if ( abfd == NULL )
bfd *abfd = bfd_openr (file_name, "pei-i386");
if (abfd == NULL)
{
bfd_perror ( "failed to open file" );
bfd_perror ("failed to open file");
return 0;
}
bfd_check_format ( abfd, bfd_object );
bfd_map_over_sections ( abfd, &select_data_section, (PTR)excl_list );
bfd_check_format (abfd, bfd_object);
bfd_map_over_sections (abfd, &select_data_section, (PTR) excl_list);
excl_list->sort_and_check ();
bfd_close ( abfd );
bfd_close (abfd);
return 1;
}

View File

@ -30,7 +30,7 @@ static BOOL close_handle (HANDLE h, DWORD ok);
#define CloseHandle(h) close_handle(h, 0)
struct child_list
{
{
DWORD id;
HANDLE hproc;
int saw_stars;
@ -38,9 +38,11 @@ struct child_list
long long start_time;
DWORD last_usecs;
struct child_list *next;
child_list () : id (0), hproc (NULL), saw_stars (0), nfields (0),
start_time (0), last_usecs (0), next (NULL) {}
};
child_list ():id (0), hproc (NULL), saw_stars (0), nfields (0),
start_time (0), last_usecs (0), next (NULL)
{
}
};
child_list children;
@ -85,7 +87,7 @@ DWORD lastid = 0;
HANDLE lasth;
#define PROCFLAGS \
PROCESS_ALL_ACCESS /*(PROCESS_DUP_HANDLE | PROCESS_TERMINATE | PROCESS_VM_READ | PROCESS_VM_WRITE)*/
PROCESS_ALL_ACCESS /*(PROCESS_DUP_HANDLE | PROCESS_TERMINATE | PROCESS_VM_READ | PROCESS_VM_WRITE) */
static void
add_child (DWORD id, HANDLE hproc)
{
@ -101,7 +103,7 @@ static child_list *
get_child (DWORD id)
{
child_list *c;
for (c = &children; (c = c->next) != NULL; )
for (c = &children; (c = c->next) != NULL;)
if (c->id == id)
return c;
@ -140,9 +142,16 @@ public:
alloc = 0;
buf = NULL;
}
~linebuf () {if (buf) free (buf);}
~linebuf ()
{
if (buf)
free (buf);
}
void add (const char *what, int len);
void add (const char *what) {add (what, strlen (what));}
void add (const char *what)
{
add (what, strlen (what));
}
void prepend (const char *what, int len);
};
@ -180,7 +189,7 @@ linebuf::prepend (const char *what, int len)
}
static void
make_command_line (linebuf& one_line, char **argv)
make_command_line (linebuf & one_line, char **argv)
{
for (; *argv; argv++)
{
@ -240,26 +249,25 @@ create_child (char **argv)
memset (&si, 0, sizeof (si));
si.cb = sizeof (si);
/* cygwin32_conv_to_win32_path (exec_file, real_path);*/
/* cygwin32_conv_to_win32_path (exec_file, real_path); */
flags = forkdebug ? 0 : DEBUG_ONLY_THIS_PROCESS;
flags |= /*CREATE_NEW_PROCESS_GROUP | */CREATE_DEFAULT_ERROR_MODE | DEBUG_PROCESS;
flags |=
/*CREATE_NEW_PROCESS_GROUP | */ CREATE_DEFAULT_ERROR_MODE | DEBUG_PROCESS;
make_command_line (one_line, argv);
SetConsoleCtrlHandler (NULL, 0);
ret = CreateProcess (0,
one_line.buf,/* command line */
ret = CreateProcess (0, one_line.buf, /* command line */
NULL, /* Security */
NULL, /* thread */
TRUE, /* inherit handles */
flags, /* start flags */
NULL,
NULL, /* current directory */
&si,
&pi);
NULL, NULL, /* current directory */
&si, &pi);
if (!ret)
error (0, "error creating process %s, (error %d)", *argv, GetLastError());
error (0, "error creating process %s, (error %d)", *argv,
GetLastError ());
CloseHandle (pi.hThread);
CloseHandle (pi.hProcess);
@ -294,9 +302,7 @@ output_winerror (FILE *ofile, char *s)
NULL,
errnum,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) buf,
sizeof (buf),
NULL))
(LPTSTR) buf, sizeof (buf), NULL))
return 0;
/* Get rid the trailing CR/NL pair. */
@ -331,7 +337,7 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile)
DWORD nbytes;
child_list *child = get_child (id);
HANDLE hchild = child->hproc;
#define INTROLEN (sizeof (alen) - 1)
#define INTROLEN (sizeof (alen) - 1)
if (id == lastid && hchild != lasth)
warn (0, "%p != %p", hchild, lasth);
@ -341,7 +347,8 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile)
#ifndef DEBUGGING
return;
#else
error (0, "couldn't get message length from subprocess %d<%p>, windows error %d",
error (0,
"couldn't get message length from subprocess %d<%p>, windows error %d",
id, hchild, GetLastError ());
#endif
@ -379,7 +386,8 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile)
DWORD new_flag = 1;
if (!WriteProcessMemory (hchild, (LPVOID) n, &new_flag,
sizeof (new_flag), &nbytes))
error (0, "couldn't write strace flag to subprocess, windows error %d",
error (0,
"couldn't write strace flag to subprocess, windows error %d",
GetLastError ());
return;
}
@ -387,7 +395,7 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile)
char *origs = s;
if (mask & n)
/* got it */;
/* got it */ ;
else if (!(mask & _STRACE_ALL) || (n & _STRACE_NOTALL))
return; /* This should not be included in "all" output */
@ -459,8 +467,10 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile)
if (*s == '*')
{
SYSTEMTIME *st = syst (child->start_time);
fprintf (ofile, "Date/Time: %d-%02d-%02d %02d:%02d:%02d\n",
st->wYear, st->wMonth, st->wDay, st->wHour, st->wMinute, st->wSecond);
fprintf (ofile,
"Date/Time: %d-%02d-%02d %02d:%02d:%02d\n",
st->wYear, st->wMonth, st->wDay, st->wHour,
st->wMinute, st->wSecond);
child->saw_stars++;
}
}
@ -471,7 +481,7 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile)
char intbuf[40];
if (child->saw_stars < 2 || s != origs)
/* Nothing */;
/* Nothing */ ;
else if (hhmmss)
{
s = ptrest - 9;
@ -537,7 +547,8 @@ proc_child (unsigned mask, FILE *ofile)
remove_child (ev.dwProcessId);
break;
case EXCEPTION_DEBUG_EVENT:
if (ev.u.Exception.ExceptionRecord.ExceptionCode != STATUS_BREAKPOINT)
if (ev.u.Exception.ExceptionRecord.ExceptionCode !=
STATUS_BREAKPOINT)
{
status = DBG_EXCEPTION_NOT_HANDLED;
#if 0
@ -566,7 +577,7 @@ dostrace (unsigned mask, FILE *ofile, char **argv)
}
int
main(int argc, char **argv)
main (int argc, char **argv)
{
unsigned mask = 0;
FILE *ofile = NULL;
@ -627,7 +638,7 @@ static BOOL
close_handle (HANDLE h, DWORD ok)
{
child_list *c;
for (c = &children; (c = c->next) != NULL; )
for (c = &children; (c = c->next) != NULL;)
if (c->hproc == h && c->id != ok)
error (0, "Closing child handle %p", h);
return CloseHandle (h);

View File

@ -27,13 +27,18 @@ static void
usage (void)
{
fprintf (stderr, "Usage %s [-s] <posixpath>\n", progname);
fprintf (stderr, "-s = remove mount point from system-wide registry location\n");
fprintf (stderr,
"-s = remove mount point from system-wide registry location\n");
fprintf (stderr, "\n");
fprintf (stderr, "--remove-all-mounts = remove all mounts\n");
fprintf (stderr, "--remove-auto-mounts = remove all automatically mounted mounts\n");
fprintf (stderr, "--remove-user-mounts = remove all mounts in the current user mount registry area, including auto mounts\n");
fprintf (stderr, "--remove-system-mounts = remove all mounts in the system-wide mount registry area\n");
fprintf (stderr, "[-s] --remove-cygdrive-prefix = remove cygdrive path prefix\n");
fprintf (stderr,
"--remove-auto-mounts = remove all automatically mounted mounts\n");
fprintf (stderr,
"--remove-user-mounts = remove all mounts in the current user mount registry area, including auto mounts\n");
fprintf (stderr,
"--remove-system-mounts = remove all mounts in the system-wide mount registry area\n");
fprintf (stderr,
"[-s] --remove-cygdrive-prefix = remove cygdrive path prefix\n");
exit (1);
}
@ -194,7 +199,7 @@ remove_all_system_mounts ()
static void
remove_cygdrive_prefix (int flags)
{
int res = cygwin_umount(NULL, flags | MOUNT_AUTO);
int res = cygwin_umount (NULL, flags | MOUNT_AUTO);
if (res)
error ("remove_cygdrive_prefix");
}