WinDBG/Exts/CodeAnalyzer/gdbplus/gdb-7.7/gdb/gdb_dep.c
// For a live process, read the process's memory map from /proc
// when create is true, build ca_segments
// when create is false, return true if process's regions haven't changed a bit
For a live process, read the process's memory map from /proc
when create is true, build ca_segments
when create is false, return true if process's regions haven't changed a bit
For a live process read the process ' s memory map from / proc when create is true build ca_segments when create is false return true if process ' s regions haven ' t changed a bit
static CA_BOOL linux_nat_find_memory_regions(CA_BOOL create)
{
	int pid = ptid_get_pid (inferior_ptid);
	char mapsfilename[MAXPATHLEN];
	FILE *mapsfile;
	long long addr, endaddr, offset, inode;
	char permissions[8], device[8], filename[MAXPATHLEN];
	unsigned int count = 0;
	sprintf (mapsfilename, "/proc/%d/maps", pid);
	if ((mapsfile = fopen (mapsfilename, "r")) == NULL)
	{
		fprintf_filtered (gdb_stdout, "Could not open %s\n", mapsfilename);
		return CA_FALSE;
	}
	while (read_mapping (mapsfile, &addr, &endaddr, &permissions[0],
		   &offset, &device[0], &inode, &filename[0]))
	{
		int read, write, exec;
		read = (strchr (permissions, 'r') != 0);
		write = (strchr (permissions, 'w') != 0);
		exec = (strchr (permissions, 'x') != 0);
		if (create)
			add_one_segment(addr, endaddr - addr, read, write, exec);
		else if (count >= g_segment_count
			|| g_segments[count].m_vaddr != addr || g_segments[count].m_vsize != endaddr - addr
			|| g_segments[count].m_read != read || g_segments[count].m_write != write || g_segments[count].m_exec != exec)
		{
			fclose(mapsfile);
			return CA_FALSE;
		}
		count++;
	}
	fclose(mapsfile);
	return CA_TRUE;
}
static CA_BOOL linux_nat_find_memory_regions ( CA_BOOL create ) { int pid = ptid_get_pid ( inferior_ptid ) ; char mapsfilename [ MAXPATHLEN ] ; FILE * mapsfile ; long long addr , endaddr , offset , inode ; char permissions [ 8 ] , device [ 8 ] , filename [ MAXPATHLEN ] ; unsigned int count = 0 ; sprintf ( mapsfilename , " " , pid ) ; if ( ( mapsfile = fopen ( mapsfilename , " " ) ) == NULL ) { fprintf_filtered ( gdb_stdout , " \n " , mapsfilename ) ; return CA_FALSE ; } while ( read_mapping ( mapsfile , & addr , & endaddr , & permissions [ 0 ] , & offset , & device [ 0 ] , & inode , & filename [ 0 ] ) ) { int read , write , exec ; read = ( strchr ( permissions , ' ' ) != 0 ) ; write = ( strchr ( permissions , ' ' ) != 0 ) ; exec = ( strchr ( permissions , ' ' ) != 0 ) ; if ( create ) add_one_segment ( addr , endaddr - addr , read , write , exec ) ; else if ( count >= g_segment_count || g_segments [ count ] . m_vaddr != addr || g_segments [ count ] . m_vsize != endaddr - addr || g_segments [ count ] . m_read != read || g_segments [ count ] . m_write != write || g_segments [ count ] . m_exec != exec ) { fclose ( mapsfile ) ; return CA_FALSE ; } count ++ ; } fclose ( mapsfile ) ; return CA_TRUE ; }
For a live process, read the process's memory map from /proc
when create is true, build ca_segments
when create is false, return true if process's regions haven't changed a bit
For a live process read the process ' s memory map from / proc when create is true build ca_segments when create is false return true if process ' s regions haven ' t changed a bit
/* Compose the filename for the /proc memory map, and open it.  */ /* Now iterate until end-of-file.  */ /* Get the segment's permissions.  */