OSDN Git Service

* cygpath.cc (get_device_name): Fix path length test.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / utils / dumper.h
1 /* dumper.h
2
3    Copyright 1999,2001 Red Hat Inc.
4
5    Written by Egor Duda <deo@logos-m.ru>
6
7    This file is part of Cygwin.
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License (file COPYING.dumper) for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
22
23 #ifndef _DUMPER_H_
24 #define _DUMPER_H_
25
26 #include <windows.h>
27
28 typedef struct
29 {
30   LPBYTE base;
31   DWORD size;
32 } process_mem_region;
33
34 typedef struct
35 {
36   DWORD tid;
37   HANDLE hThread;
38   CONTEXT context;
39 } process_thread;
40
41 typedef struct
42 {
43   LPVOID base_address;
44   char* name;
45 } process_module;
46
47 enum process_entity_type
48 {
49   pr_ent_memory,
50   pr_ent_thread,
51   pr_ent_module
52 };
53
54 typedef struct _process_entity
55 {
56   process_entity_type type;
57   union
58     {
59       process_thread thread;
60       process_mem_region memory;
61       process_module module;
62     } u;
63   asection* section;
64   struct _process_entity* next;
65 } process_entity;
66
67 class exclusion
68 {
69 public:
70   int last;
71   int size;
72   int step;
73   process_mem_region* region;
74
75   exclusion ( int step ) { last = size = 0;
76                            this->step = step;
77                            region = NULL; }
78   ~exclusion () { free ( region ); }
79   int add ( LPBYTE mem_base, DWORD mem_size );
80   int sort_and_check ();
81 };
82
83 #define PAGE_BUFFER_SIZE 4096
84
85 class dumper
86 {
87   DWORD pid;
88   DWORD tid; /* thread id of active thread */
89   HANDLE hProcess;
90   process_entity* list;
91   process_entity* last;
92   exclusion* excl_list;
93
94   char* file_name;
95   bfd* core_bfd;
96
97   asection* status_section;
98
99   int memory_num;
100   int module_num;
101   int thread_num;
102
103   void close ();
104   void dumper_abort ();
105
106   process_entity* add_process_entity_to_list ( process_entity_type type );
107   int add_thread ( DWORD tid, HANDLE hThread );
108   int add_mem_region ( LPBYTE base, DWORD size );
109
110   /* break mem_region by excl_list and add add all subregions */
111   int split_add_mem_region ( LPBYTE base, DWORD size );
112
113   int add_module ( LPVOID base_address );
114
115   int collect_memory_sections ();
116   int dump_memory_region ( asection* to, process_mem_region* memory );
117   int dump_thread ( asection* to, process_thread* thread );
118   int dump_module ( asection* to, process_module* module );
119
120 public:
121   int sane ();
122
123   int collect_process_information ();
124   void print_core_section_list ();
125
126   dumper ( DWORD pid, DWORD tid, const char* name );
127   ~dumper ();
128
129   int init_core_dump ();
130   int prepare_core_dump ();
131   int write_core_dump ();
132 };
133
134 extern int deb_printf ( const char* format, ... );
135
136 extern char* psapi_get_module_name ( HANDLE hProcess, DWORD BaseAddress );
137
138 extern int parse_pe ( const char* file_name, exclusion* excl_list );
139
140 extern BOOL verbose;
141
142 #endif