WinDBG/Exts/CodeAnalyzer/gdbplus/gdb-1824/src/gdb/segment.c
//  Split a segment into two parts at given address
Split a segment into two parts at given address
Split a segment into two parts at given address
static void split_segment(struct ca_segment* segment, address_t addr)
{
	unsigned int index;
	size_t old_vsize, old_fsize;
	struct ca_segment* next;
	if (addr < segment->m_vaddr || addr >= segment->m_vaddr + segment->m_vsize)
		return;
	index = segment - &g_segments[0];
	if (index < g_segment_count - 1)
	{
		unsigned int i;
		for (i = g_segment_count - 1; ; i--)
		{
			memcpy(&g_segments[i + 1], &g_segments[i], sizeof(struct ca_segment));
			if (i == index)
				break;
		}
	}
	g_segment_count++;
	old_vsize = segment->m_vsize;
	old_fsize = segment->m_fsize;
	segment->m_vsize = addr - segment->m_vaddr;
	if (segment->m_fsize > segment->m_vsize)
		segment->m_fsize = segment->m_vsize;
	next = segment + 1;
	next->m_vaddr = addr;
	next->m_vsize = old_vsize - segment->m_vsize;
	if (segment->m_faddr)
		next->m_faddr = segment->m_faddr + segment->m_vsize;
	if (old_fsize > segment->m_fsize)
		next->m_fsize = old_fsize - segment->m_fsize;
	if (segment->m_module_name)
		next->m_module_name = strdup(segment->m_module_name);
	if (next->m_ptr_bitvec)
	{
		if (next->m_fsize > 0)
		{
			size_t ptr_sz = g_ptr_bit >> 3;
			next->m_ptr_bitvec = (unsigned int*)((char*)segment->m_ptr_bitvec + (segment->m_fsize/ptr_sz >> 3));
		}
		else
			next->m_ptr_bitvec = NULL;
	}
}
static void split_segment ( struct ca_segment * segment , address_t addr ) { unsigned int index ; size_t old_vsize , old_fsize ; struct ca_segment * next ; if ( addr < segment -> m_vaddr || addr >= segment -> m_vaddr + segment -> m_vsize ) return ; index = segment - & g_segments [ 0 ] ; if ( index < g_segment_count - 1 ) { unsigned int i ; for ( i = g_segment_count - 1 ; ; i -- ) { memcpy ( & g_segments [ i + 1 ] , & g_segments [ i ] , sizeof ( struct ca_segment ) ) ; if ( i == index ) break ; } } g_segment_count ++ ; old_vsize = segment -> m_vsize ; old_fsize = segment -> m_fsize ; segment -> m_vsize = addr - segment -> m_vaddr ; if ( segment -> m_fsize > segment -> m_vsize ) segment -> m_fsize = segment -> m_vsize ; next = segment + 1 ; next -> m_vaddr = addr ; next -> m_vsize = old_vsize - segment -> m_vsize ; if ( segment -> m_faddr ) next -> m_faddr = segment -> m_faddr + segment -> m_vsize ; if ( old_fsize > segment -> m_fsize ) next -> m_fsize = old_fsize - segment -> m_fsize ; if ( segment -> m_module_name ) next -> m_module_name = strdup ( segment -> m_module_name ) ; if ( next -> m_ptr_bitvec ) { if ( next -> m_fsize > 0 ) { size_t ptr_sz = g_ptr_bit >> 3 ; next -> m_ptr_bitvec = ( unsigned int * ) ( ( char * ) segment -> m_ptr_bitvec + ( segment -> m_fsize / ptr_sz >> 3 ) ) ; } else next -> m_ptr_bitvec = NULL ; } }
Split a segment into two parts at given address
Split a segment into two parts at given address
// Sanity check // Move down segments after me // Adjust the first part // Adjust the second part