This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH/pie] Add param to memory regions iterator function
- From: Elena Zannoni <ezannoni at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Mon, 29 Sep 2003 18:51:18 -0400
- Subject: [PATCH/pie] Add param to memory regions iterator function
[on ezannoni_pie-20030916-branch]
This patch adds a new parameter to the function that gdb uses to
iterate over the memory regions stored in /proc/<PID>/maps. I.e. now
that function also extracts and records the filename from the maps
file.
I am going to use that somewhere else to find out where the main
executable got loaded.
elena
2003-09-29 Elena Zannoni <ezannoni@redhat.com>
* exec.c (exec_set_find_memory_regions): Update parameter list.
* defs.h (exec_set_find_memory_regions): Update parameter list.
* fbsd-proc.c (fbsd_find_memory_regions): Likewise. Update call to
function parameter.
* gcore.c (gcore_create_callback): Update paramter list.
(objfile_find_memory_regions): Update parameter list. Update calls
to function parameter.
* gnu-nat.c (gnu_find_memory_regions): Update parameter
list. Update calls to function parameter.
* inftarg.c (inftarg_set_find_memory_regions): Update parameter
list.
* linux-proc.c (read_mapping): Prune the leading whitespaces in
the filename.
(linux_find_memory_regions): Update parameter list. Update call to
function parameter.
* procfs.c (find_memory_regions_callback): Update paremeters and
calls.
(proc_find_memory_regions): Update parameters.
* sol-thread.c (sol_find_memory_regions): Update parameter list.
* target.h (struct target_ops): Update definition of
to_find_memory_regions field.
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.130
diff -u -p -r1.130 defs.h
--- defs.h 12 Sep 2003 18:40:16 -0000 1.130
+++ defs.h 29 Sep 2003 22:34:09 -0000
@@ -607,7 +607,7 @@ extern void exec_set_section_offsets (bf
extern void exec_set_find_memory_regions (int (*) (int (*) (CORE_ADDR,
unsigned long,
int, int, int,
- void *),
+ char *, void *),
void *));
/* Possible lvalue types. Like enum language, this should be in
Index: exec.c
===================================================================
RCS file: /cvs/src/src/gdb/exec.c,v
retrieving revision 1.29
diff -u -p -r1.29 exec.c
--- exec.c 3 Sep 2003 21:01:44 -0000 1.29
+++ exec.c 29 Sep 2003 22:34:10 -0000
@@ -700,7 +700,7 @@ extern void
exec_set_find_memory_regions (int (*func) (int (*) (CORE_ADDR,
unsigned long,
int, int, int,
- void *),
+ char *, void *),
void *))
{
exec_ops.to_find_memory_regions = func;
Index: fbsd-proc.c
===================================================================
RCS file: /cvs/src/src/gdb/fbsd-proc.c,v
retrieving revision 1.3
diff -u -p -r1.3 fbsd-proc.c
--- fbsd-proc.c 2 Aug 2002 20:51:21 -0000 1.3
+++ fbsd-proc.c 29 Sep 2003 22:34:10 -0000
@@ -75,7 +75,7 @@ static int
fbsd_find_memory_regions (int (*func) (CORE_ADDR,
unsigned long,
int, int, int,
- void *),
+ char *, void *),
void *obfd)
{
pid_t pid = ptid_get_pid (inferior_ptid);
@@ -114,7 +114,7 @@ fbsd_find_memory_regions (int (*func) (C
}
/* Invoke the callback function to create the corefile segment. */
- func (start, size, read, write, exec, obfd);
+ func (start, size, read, write, exec, NULL, obfd);
}
fclose (mapfile);
Index: gcore.c
===================================================================
RCS file: /cvs/src/src/gdb/gcore.c,v
retrieving revision 1.11
diff -u -p -r1.11 gcore.c
--- gcore.c 4 Sep 2003 21:05:49 -0000 1.11
+++ gcore.c 29 Sep 2003 22:34:10 -0000
@@ -338,7 +338,8 @@ make_mem_sec (bfd *obfd, bfd_vma addr, b
static int
gcore_create_callback (CORE_ADDR vaddr, unsigned long size,
- int read, int write, int exec, void *data)
+ int read, int write, int exec, char *filename,
+ void *data)
{
flagword flags = 0;
@@ -360,7 +361,7 @@ gcore_create_callback (CORE_ADDR vaddr,
static int
objfile_find_memory_regions (int (*func) (CORE_ADDR, unsigned long,
- int, int, int, void *),
+ int, int, int, char *, void *),
void *obfd)
{
/* Use objfile data to create memory sections. */
@@ -385,6 +386,7 @@ objfile_find_memory_regions (int (*func)
1, /* All sections will be readable. */
(flags & SEC_READONLY) == 0, /* Writable. */
(flags & SEC_CODE) != 0, /* Executable. */
+ NULL,
obfd);
if (ret != 0)
return ret;
@@ -397,6 +399,7 @@ objfile_find_memory_regions (int (*func)
1, /* Stack section will be readable. */
1, /* Stack section will be writable. */
0, /* Stack section will not be executable. */
+ NULL,
obfd);
/* Make a heap segment. */
@@ -405,6 +408,7 @@ objfile_find_memory_regions (int (*func)
1, /* Heap section will be readable. */
1, /* Heap section will be writable. */
0, /* Heap section will not be executable. */
+ NULL,
obfd);
return 0;
Index: gnu-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/gnu-nat.c,v
retrieving revision 1.27
diff -u -p -r1.27 gnu-nat.c
--- gnu-nat.c 9 Sep 2003 03:14:02 -0000 1.27
+++ gnu-nat.c 29 Sep 2003 22:34:13 -0000
@@ -2473,7 +2473,7 @@ static int
gnu_find_memory_regions (int (*func) (CORE_ADDR,
unsigned long,
int, int, int,
- void *),
+ char *, void *),
void *data)
{
error_t err;
@@ -2531,6 +2531,7 @@ gnu_find_memory_regions (int (*func) (CO
last_protection & VM_PROT_READ,
last_protection & VM_PROT_WRITE,
last_protection & VM_PROT_EXECUTE,
+ NULL,
data);
last_region_address = region_address;
last_region_end = region_address += region_length;
Index: inftarg.c
===================================================================
RCS file: /cvs/src/src/gdb/inftarg.c,v
retrieving revision 1.17
diff -u -p -r1.17 inftarg.c
--- inftarg.c 7 Feb 2003 04:21:34 -0000 1.17
+++ inftarg.c 29 Sep 2003 22:34:14 -0000
@@ -623,7 +623,7 @@ extern void
inftarg_set_find_memory_regions (int (*func) (int (*) (CORE_ADDR,
unsigned long,
int, int, int,
- void *),
+ char *, void *),
void *))
{
child_ops.to_find_memory_regions = func;
Index: linux-proc.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-proc.c,v
retrieving revision 1.19
diff -u -p -r1.19 linux-proc.c
--- linux-proc.c 7 Sep 2003 18:49:44 -0000 1.19
+++ linux-proc.c 29 Sep 2003 22:34:14 -0000
@@ -81,6 +81,8 @@ read_mapping (FILE *mapfile,
long long *offset,
char *device, long long *inode, char *filename)
{
+ char tmp_filename[MAXPATHLEN];
+ char *p;
int ret = fscanf (mapfile, "%llx-%llx %s %llx %s %llx",
addr, endaddr, permissions, offset, device, inode);
@@ -93,7 +95,13 @@ read_mapping (FILE *mapfile,
filename.
Note the filename is used for informational purposes only. */
- ret += fscanf (mapfile, "%[^\n]\n", filename);
+ ret += fscanf (mapfile, "%[^\n]\n", tmp_filename);
+
+ /* Skip the spaces at the beginning of the filename. */
+ p = tmp_filename;
+ while (*p == ' ')
+ p++;
+ strcpy (filename, p);
}
else
{
@@ -112,7 +120,8 @@ read_mapping (FILE *mapfile,
static int
linux_find_memory_regions (int (*func) (CORE_ADDR,
unsigned long,
- int, int, int, void *), void *obfd)
+ int, int, int, char *, void *),
+ void *obfd)
{
long long pid = PIDGET (inferior_ptid);
char mapsfilename[MAXPATHLEN];
@@ -155,7 +164,7 @@ linux_find_memory_regions (int (*func) (
}
/* Invoke the callback function to create the corefile segment. */
- func (addr, size, read, write, exec, obfd);
+ func (addr, size, read, write, exec, filename, obfd);
}
fclose (mapsfile);
return 0;
Index: procfs.c
===================================================================
RCS file: /cvs/src/src/gdb/procfs.c,v
retrieving revision 1.46
diff -u -p -r1.46 procfs.c
--- procfs.c 29 Apr 2003 01:49:47 -0000 1.46
+++ procfs.c 29 Sep 2003 22:34:19 -0000
@@ -136,7 +136,7 @@ char *procfs_pid_to_str (ptid_t);
static int proc_find_memory_regions (int (*) (CORE_ADDR,
unsigned long,
int, int, int,
- void *),
+ char *, void *),
void *);
static char * procfs_make_note_section (bfd *, int *);
@@ -5433,7 +5433,7 @@ proc_iterate_over_mappings (int (*func)
* int callback (CORE_ADDR vaddr,
* unsigned long size,
* int read, int write, int execute,
- * void *data);
+ * char *filename, void *data);
*
* Returns the integer value returned by the callback.
*/
@@ -5443,7 +5443,7 @@ find_memory_regions_callback (struct prm
int (*func) (CORE_ADDR,
unsigned long,
int, int, int,
- void *),
+ char *, void *),
void *data)
{
return (*func) ((CORE_ADDR) map->pr_vaddr,
@@ -5451,6 +5451,7 @@ find_memory_regions_callback (struct prm
(map->pr_mflags & MA_READ) != 0,
(map->pr_mflags & MA_WRITE) != 0,
(map->pr_mflags & MA_EXEC) != 0,
+ NULL,
data);
}
@@ -5463,7 +5464,8 @@ find_memory_regions_callback (struct prm
* unsigned long size,
* int read, TRUE if region is readable by the child
* int write, TRUE if region is writable by the child
- * int execute TRUE if region is executable by the child.
+ * int execute TRUE if region is executable by the child
+ * char *filename.
*
* Stops iterating and returns the first non-zero value
* returned by the callback.
@@ -5473,7 +5475,7 @@ static int
proc_find_memory_regions (int (*func) (CORE_ADDR,
unsigned long,
int, int, int,
- void *),
+ char *, void *),
void *data)
{
procinfo *pi = find_procinfo_or_die (PIDGET (inferior_ptid), 0);
Index: sol-thread.c
===================================================================
RCS file: /cvs/src/src/gdb/sol-thread.c,v
retrieving revision 1.37
diff -u -p -r1.37 sol-thread.c
--- sol-thread.c 6 Sep 2003 21:09:21 -0000 1.37
+++ sol-thread.c 29 Sep 2003 22:34:20 -0000
@@ -1517,7 +1517,7 @@ static int
sol_find_memory_regions (int (*func) (CORE_ADDR,
unsigned long,
int, int, int,
- void *),
+ char *, void *),
void *data)
{
return procfs_ops.to_find_memory_regions (func, data);
Index: target.h
===================================================================
RCS file: /cvs/src/src/gdb/target.h,v
retrieving revision 1.41
diff -u -p -r1.41 target.h
--- target.h 17 Jun 2003 20:28:13 -0000 1.41
+++ target.h 29 Sep 2003 22:34:22 -0000
@@ -320,7 +320,7 @@ struct target_ops
int (*to_find_memory_regions) (int (*) (CORE_ADDR,
unsigned long,
int, int, int,
- void *),
+ char *, void *),
void *);
char * (*to_make_corefile_notes) (bfd *, int *);