dfloc.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,260 行 · 第 1/3 页
C
1,260 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: DWARF location processing for the DIP interface.
*
****************************************************************************/
#include <string.h>
#include "dfdip.h"
#include "dfld.h"
#include "dfmod.h"
#include "dfaddr.h"
#include "dfaddsym.h"
#include "dfsym.h"
#include "dftype.h"
dip_status SafeDCItemLocation( location_context *lc, context_item ci, location_list *ll ){
dr_dbg_handle old_handle;
dip_status rc;
old_handle = DRGetDebug();
rc = DCItemLocation( lc, ci, ll );
DRSetDebug( old_handle );
return( rc );
}
static void LocationInit( location_list *ll ){
ll->num = 0;
ll->flags = 0;
}
static void LocationLast( location_list *ll ){
int num;
num = ll->num;
if( --num >= 0 ){
ll->e[num].bit_length = 0;
}
}
extern void LocationCreate( location_list *ll, location_type lt, void *d ){
ll->num = 1;
ll->flags = 0;
ll->e[0].bit_start = 0;
ll->e[0].bit_length = 0;
ll->e[0].type = lt;
if( lt == LT_ADDR ) {
ll->e[0].u.addr = *(address *)d;
} else {
ll->e[0].u.p = d;
}
}
static void LocationJoin( location_list *to, location_list *from ){
int next;
next = to->num;
memcpy( &to->e[next], &from->e[0], from->num*sizeof( from->e[0] ) );
to->flags |= from->flags;
to->num += from->num;
}
extern void LocationAdd( location_list *ll, long sbits ){
location_entry *le;
unsigned long add;
unsigned num;
unsigned long bits;
bits = sbits;
if( sbits < 0 ) {
bits = -bits;
add = (bits + 7) / 8;
if( ll->e[0].type == LT_ADDR ) {
ll->e[0].u.addr.mach.offset -= add;
} else {
ll->e[0].u.p = (byte *)ll->e[0].u.p - add;
}
bits = 8 - (bits % 8);
bits %= 8;
}
num = 0;
le = &ll->e[0];
for( ;; ) {
if( le->bit_length == 0 ) break;
if( le->bit_length > bits ) break;
bits -= le->bit_length;
++num;
}
if( num != 0 ) {
ll->num -= num;
memcpy( &ll->e[0], le, ll->num * sizeof( ll->e[0] ) );
}
add = bits / 8;
bits = bits % 8;
ll->e[0].bit_start += bits;
if( ll->e[0].bit_length != 0 ) ll->e[0].bit_length -= bits;
if( ll->e[0].type == LT_ADDR ) {
ll->e[0].u.addr.mach.offset += add;
} else {
ll->e[0].u.p = (byte *)ll->e[0].u.p + add;
}
}
extern void LocationTrunc( location_list *ll, unsigned bits )
{
unsigned i;
if( bits == 0 ) return;
i = 0;
for( ;; ) {
if( i >= ll->num ) return;
if( ll->e[i].bit_length == 0 ) break;
if( ll->e[i].bit_length > bits ) break;
bits -= ll->e[i].bit_length;
++i;
}
ll->e[i].bit_length = bits;
}
typedef enum {
#define DW_REG( __n ) DW_X86_##__n,
#include "dwreginf.h"
DW_REG( MAX )
#undef DW_REG
}dw_X86_regs;
typedef struct {
unsigned ci : 5;
unsigned start : 4;
unsigned len : 7;
} reg_entry;
/* WARNING: Must be kept in sync with dwreginf.h included above */
static reg_entry const CLRegX86[DW_X86_MAX] = {
{ CI_EAX, 0, 32 }, //eax
{ CI_ECX, 0, 32 }, //ecx
{ CI_EDX, 0, 32 }, //edx
{ CI_EBX, 0, 32 }, //ebx
{ CI_ESP, 0, 32 }, //esp
{ CI_EBP, 0, 32 }, //ebp
{ CI_ESI, 0, 32 }, //esi
{ CI_EDI, 0, 32 }, //edi
{ CI_EIP, 0, 32 }, //eip
{ CI_EFL, 0, 32 }, //eflags
{ 0 , 0, 0 }, //trapno
{ CI_ST0, 0, 80 }, //st0
{ CI_ST1, 0, 80 }, //st1
{ CI_ST2, 0, 80 }, //st2
{ CI_ST3, 0, 80 }, //st3
{ CI_ST4, 0, 80 }, //st4
{ CI_ST5, 0, 80 }, //st5
{ CI_ST6, 0, 80 }, //st6
{ CI_ST7, 0, 80 }, //st7
{ CI_EAX, 0, 8 }, //al
{ CI_EAX, 8, 8 }, //ah
{ CI_EBX, 0, 8 }, //bl
{ CI_EBX, 8, 8 }, //bh
{ CI_ECX, 0, 8 }, //cl
{ CI_ECX, 8, 8 }, //ch
{ CI_EDX, 0, 8 }, //dl
{ CI_EDX, 8, 8 }, //dh
{ CI_EAX, 0, 16 }, //ax
{ CI_EBX, 0, 16 }, //bx
{ CI_ECX, 0, 16 }, //cx
{ CI_EDX, 0, 16 }, //dx
{ CI_ESI, 0, 16 }, //si
{ CI_EDI, 0, 16 }, //di
{ CI_EBP, 0, 16 }, //bp
{ CI_ESP, 0, 16 }, //sp
{ CI_CS, 0, 16 }, //cs
{ CI_SS, 0, 16 }, //ss
{ CI_DS, 0, 16 }, //ds
{ CI_ES, 0, 16 }, //es
{ CI_FS, 0, 16 }, //fs
{ CI_GS, 0, 16 }, //gs
};
typedef enum {
#define DW_REG( __n ) DW_AXP_##__n,
#include "dwregaxp.h"
DW_REG( MAX )
#undef DW_REG
}dw_axp_regs;
/* WARNING: Must be kept in sync with dwregaxp.h included above */
static uint_16 const CLRegAXP[DW_AXP_MAX] = {
/* Alpha architecture */
CI_AXP_r0, //DW_AXP_r0
CI_AXP_r1, //DW_AXP_r1
CI_AXP_r2, //DW_AXP_r2
CI_AXP_r3, //DW_AXP_r3
CI_AXP_r4, //DW_AXP_r4
CI_AXP_r5, //DW_AXP_r5
CI_AXP_r6, //DW_AXP_r6
CI_AXP_r7, //DW_AXP_r7
CI_AXP_r8, //DW_AXP_r8
CI_AXP_r9, //DW_AXP_r9
CI_AXP_r10, //DW_AXP_r10
CI_AXP_r11, //DW_AXP_r11
CI_AXP_r12, //DW_AXP_r12
CI_AXP_r13, //DW_AXP_r13
CI_AXP_r14, //DW_AXP_r14
CI_AXP_r15, //DW_AXP_r15
CI_AXP_r16, //DW_AXP_r16
CI_AXP_r17, //DW_AXP_r17
CI_AXP_r18, //DW_AXP_r18
CI_AXP_r19, //DW_AXP_r19
CI_AXP_r20, //DW_AXP_r20
CI_AXP_r21, //DW_AXP_r21
CI_AXP_r22, //DW_AXP_r22
CI_AXP_r23, //DW_AXP_r23
CI_AXP_r24, //DW_AXP_r24
CI_AXP_r25, //DW_AXP_r25
CI_AXP_r26, //DW_AXP_r26
CI_AXP_r27, //DW_AXP_r27
CI_AXP_r28, //DW_AXP_r28
CI_AXP_r29, //DW_AXP_r29
CI_AXP_r30, //DW_AXP_r30
CI_AXP_r31, //DW_AXP_r31
CI_AXP_f0, //DW_AXP_f0
CI_AXP_f1, //DW_AXP_f1
CI_AXP_f2, //DW_AXP_f2
CI_AXP_f3, //DW_AXP_f3
CI_AXP_f4, //DW_AXP_f4
CI_AXP_f5, //DW_AXP_f5
CI_AXP_f6, //DW_AXP_f6
CI_AXP_f7, //DW_AXP_f7
CI_AXP_f8, //DW_AXP_f8
CI_AXP_f9, //DW_AXP_f9
CI_AXP_f10, //DW_AXP_f10
CI_AXP_f11, //DW_AXP_f11
CI_AXP_f12, //DW_AXP_f12
CI_AXP_f13, //DW_AXP_f13
CI_AXP_f14, //DW_AXP_f14
CI_AXP_f15, //DW_AXP_f15
CI_AXP_f16, //DW_AXP_f16
CI_AXP_f17, //DW_AXP_f17
CI_AXP_f18, //DW_AXP_f18
CI_AXP_f19, //DW_AXP_f19
CI_AXP_f20, //DW_AXP_f20
CI_AXP_f21, //DW_AXP_f21
CI_AXP_f22, //DW_AXP_f22
CI_AXP_f23, //DW_AXP_f23
CI_AXP_f24, //DW_AXP_f24
CI_AXP_f25, //DW_AXP_f25
CI_AXP_f26, //DW_AXP_f26
CI_AXP_f27, //DW_AXP_f27
CI_AXP_f28, //DW_AXP_f28
CI_AXP_f29, //DW_AXP_f29
CI_AXP_f30, //DW_AXP_f30
CI_AXP_f31, //DW_AXP_f31
};
typedef enum {
#define DW_REG( __n ) DW_PPC_##__n,
#include "dwregppc.h"
DW_REG( MAX )
#undef DW_REG
} dw_ppc_regs;
typedef struct {
unsigned ci : 8;
unsigned start : 8;
unsigned len : 8;
} ppcreg_entry;
/* WARNING: Must be kept in sync with dwregppc.h included above */
static ppcreg_entry const CLRegPPC[DW_PPC_MAX] = {
/* PowerPC architecture */
{ CI_PPC_r0, 0, 32 }, //DW_PPC_r0
{ CI_PPC_r1, 0, 32 }, //DW_PPC_r1
{ CI_PPC_r2, 0, 32 }, //DW_PPC_r2
{ CI_PPC_r3, 0, 32 }, //DW_PPC_r3
{ CI_PPC_r4, 0, 32 }, //DW_PPC_r4
{ CI_PPC_r5, 0, 32 }, //DW_PPC_r5
{ CI_PPC_r6, 0, 32 }, //DW_PPC_r6
{ CI_PPC_r7, 0, 32 }, //DW_PPC_r7
{ CI_PPC_r8, 0, 32 }, //DW_PPC_r8
{ CI_PPC_r9, 0, 32 }, //DW_PPC_r9
{ CI_PPC_r10, 0, 32 }, //DW_PPC_r10
{ CI_PPC_r11, 0, 32 }, //DW_PPC_r11
{ CI_PPC_r12, 0, 32 }, //DW_PPC_r12
{ CI_PPC_r13, 0, 32 }, //DW_PPC_r13
{ CI_PPC_r14, 0, 32 }, //DW_PPC_r14
{ CI_PPC_r15, 0, 32 }, //DW_PPC_r15
{ CI_PPC_r16, 0, 32 }, //DW_PPC_r16
{ CI_PPC_r17, 0, 32 }, //DW_PPC_r17
{ CI_PPC_r18, 0, 32 }, //DW_PPC_r18
{ CI_PPC_r19, 0, 32 }, //DW_PPC_r19
{ CI_PPC_r20, 0, 32 }, //DW_PPC_r20
{ CI_PPC_r21, 0, 32 }, //DW_PPC_r21
{ CI_PPC_r22, 0, 32 }, //DW_PPC_r22
{ CI_PPC_r23, 0, 32 }, //DW_PPC_r23
{ CI_PPC_r24, 0, 32 }, //DW_PPC_r24
{ CI_PPC_r25, 0, 32 }, //DW_PPC_r25
{ CI_PPC_r26, 0, 32 }, //DW_PPC_r26
{ CI_PPC_r27, 0, 32 }, //DW_PPC_r27
{ CI_PPC_r28, 0, 32 }, //DW_PPC_r28
{ CI_PPC_r29, 0, 32 }, //DW_PPC_r29
{ CI_PPC_r30, 0, 32 }, //DW_PPC_r30
{ CI_PPC_r31, 0, 32 }, //DW_PPC_r31
{ CI_PPC_f0, 0, 64 }, //DW_PPC_f0
{ CI_PPC_f1, 0, 64 }, //DW_PPC_f1
{ CI_PPC_f2, 0, 64 }, //DW_PPC_f2
{ CI_PPC_f3, 0, 64 }, //DW_PPC_f3
{ CI_PPC_f4, 0, 64 }, //DW_PPC_f4
{ CI_PPC_f5, 0, 64 }, //DW_PPC_f5
{ CI_PPC_f6, 0, 64 }, //DW_PPC_f6
{ CI_PPC_f7, 0, 64 }, //DW_PPC_f7
{ CI_PPC_f8, 0, 64 }, //DW_PPC_f8
{ CI_PPC_f9, 0, 64 }, //DW_PPC_f9
{ CI_PPC_f10, 0, 64 }, //DW_PPC_f10
{ CI_PPC_f11, 0, 64 }, //DW_PPC_f21
{ CI_PPC_f12, 0, 64 }, //DW_PPC_f22
{ CI_PPC_f13, 0, 64 }, //DW_PPC_f23
{ CI_PPC_f14, 0, 64 }, //DW_PPC_f24
{ CI_PPC_f15, 0, 64 }, //DW_PPC_f25
{ CI_PPC_f16, 0, 64 }, //DW_PPC_f26
{ CI_PPC_f17, 0, 64 }, //DW_PPC_f27
{ CI_PPC_f18, 0, 64 }, //DW_PPC_f28
{ CI_PPC_f19, 0, 64 }, //DW_PPC_f29
{ CI_PPC_f20, 0, 64 }, //DW_PPC_f20
{ CI_PPC_f21, 0, 64 }, //DW_PPC_f21
{ CI_PPC_f22, 0, 64 }, //DW_PPC_f22
{ CI_PPC_f23, 0, 64 }, //DW_PPC_f23
{ CI_PPC_f24, 0, 64 }, //DW_PPC_f24
{ CI_PPC_f25, 0, 64 }, //DW_PPC_f25
{ CI_PPC_f26, 0, 64 }, //DW_PPC_f26
{ CI_PPC_f27, 0, 64 }, //DW_PPC_f27
{ CI_PPC_f28, 0, 64 }, //DW_PPC_f28
{ CI_PPC_f29, 0, 64 }, //DW_PPC_f29
{ CI_PPC_f30, 0, 64 }, //DW_PPC_f30
{ CI_PPC_f31, 0, 64 }, //DW_PPC_f31
};
typedef enum {
#define DW_REG( __n ) DW_MIPS_##__n,
#include "dwregmips.h"
DW_REG( MAX )
#undef DW_REG
} dw_mips_regs;
typedef struct {
unsigned ci : 8;
unsigned start : 8;
unsigned len : 8;
} mipsreg_entry;
/* WARNING: Must be kept in sync with dwregmips.h included above */
static mipsreg_entry const CLRegMIPS[DW_MIPS_MAX] = {
/* MIPS architecture */
{ CI_MIPS_r0, 0, 32 }, //DW_MIPS_r0
{ CI_MIPS_r1, 0, 32 }, //DW_MIPS_r1
{ CI_MIPS_r2, 0, 32 }, //DW_MIPS_r2
{ CI_MIPS_r3, 0, 32 }, //DW_MIPS_r3
{ CI_MIPS_r4, 0, 32 }, //DW_MIPS_r4
{ CI_MIPS_r5, 0, 32 }, //DW_MIPS_r5
{ CI_MIPS_r6, 0, 32 }, //DW_MIPS_r6
{ CI_MIPS_r7, 0, 32 }, //DW_MIPS_r7
{ CI_MIPS_r8, 0, 32 }, //DW_MIPS_r8
{ CI_MIPS_r9, 0, 32 }, //DW_MIPS_r9
{ CI_MIPS_r10, 0, 32 }, //DW_MIPS_r10
{ CI_MIPS_r11, 0, 32 }, //DW_MIPS_r11
{ CI_MIPS_r12, 0, 32 }, //DW_MIPS_r12
{ CI_MIPS_r13, 0, 32 }, //DW_MIPS_r13
{ CI_MIPS_r14, 0, 32 }, //DW_MIPS_r14
{ CI_MIPS_r15, 0, 32 }, //DW_MIPS_r15
{ CI_MIPS_r16, 0, 32 }, //DW_MIPS_r16
{ CI_MIPS_r17, 0, 32 }, //DW_MIPS_r17
{ CI_MIPS_r18, 0, 32 }, //DW_MIPS_r18
{ CI_MIPS_r19, 0, 32 }, //DW_MIPS_r19
{ CI_MIPS_r20, 0, 32 }, //DW_MIPS_r20
{ CI_MIPS_r21, 0, 32 }, //DW_MIPS_r21
{ CI_MIPS_r22, 0, 32 }, //DW_MIPS_r22
{ CI_MIPS_r23, 0, 32 }, //DW_MIPS_r23
{ CI_MIPS_r24, 0, 32 }, //DW_MIPS_r24
{ CI_MIPS_r25, 0, 32 }, //DW_MIPS_r25
{ CI_MIPS_r26, 0, 32 }, //DW_MIPS_r26
{ CI_MIPS_r27, 0, 32 }, //DW_MIPS_r27
{ CI_MIPS_r28, 0, 32 }, //DW_MIPS_r28
{ CI_MIPS_r29, 0, 32 }, //DW_MIPS_r29
{ CI_MIPS_r30, 0, 32 }, //DW_MIPS_r30
{ CI_MIPS_r31, 0, 32 }, //DW_MIPS_r31
{ CI_MIPS_f0, 0, 64 }, //DW_MIPS_f0
{ CI_MIPS_f1, 0, 64 }, //DW_MIPS_f1
{ CI_MIPS_f2, 0, 64 }, //DW_MIPS_f2
{ CI_MIPS_f3, 0, 64 }, //DW_MIPS_f3
{ CI_MIPS_f4, 0, 64 }, //DW_MIPS_f4
{ CI_MIPS_f5, 0, 64 }, //DW_MIPS_f5
{ CI_MIPS_f6, 0, 64 }, //DW_MIPS_f6
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?