123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- /*++
- Copyright (c) 2015 Minoca Corp.
- This file is licensed under the terms of the GNU General Public License
- version 3. Alternative licensing terms are available. Contact
- info@minocacorp.com for details. See the LICENSE file at the root of this
- project for complete licensing information.
- Module Name:
- dbgdwarf.c
- Abstract:
- This module implements the glue functions that connect the rest of the
- debugger to the DWARF symbol library.
- Author:
- Evan Green 17-Dec-2015
- Environment:
- Debug
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <minoca/lib/types.h>
- #include <minoca/lib/status.h>
- #include <minoca/lib/im.h>
- #include <minoca/debug/spproto.h>
- #include <minoca/debug/dbgext.h>
- #include "dbgrprof.h"
- #include "dbgapi.h"
- #include "symbols.h"
- #include "dbgrcomm.h"
- #include "dwarf.h"
- #include <assert.h>
- #include <errno.h>
- #include <stdio.h>
- #include <string.h>
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // ------------------------------------------------------------------ Functions
- //
- INT
- DwarfTargetRead (
- PDWARF_CONTEXT Context,
- ULONGLONG TargetAddress,
- ULONGLONG Size,
- ULONG AddressSpace,
- PVOID Buffer
- )
- /*++
- Routine Description:
- This routine performs a read from target memory.
- Arguments:
- Context - Supplies a pointer to the DWARF context.
- TargetAddress - Supplies the address to read from.
- Size - Supplies the number of bytes to read.
- AddressSpace - Supplies the address space identifier. Supply 0 for normal
- memory.
- Buffer - Supplies a pointer where the read data will be returned on success.
- Return Value:
- 0 on success.
- Returns an error number on failure.
- --*/
- {
- ULONG BytesRead;
- PDEBUGGER_CONTEXT DebuggerContext;
- INT Status;
- PDEBUG_SYMBOLS Symbols;
- Symbols = (((PDEBUG_SYMBOLS)Context) - 1);
- DebuggerContext = Symbols->HostContext;
- assert(DebuggerContext != NULL);
- assert(AddressSpace == 0);
- Status = DbgReadMemory(DebuggerContext,
- TRUE,
- TargetAddress,
- Size,
- Buffer,
- &BytesRead);
- if (Status != 0) {
- return Status;
- }
- if (BytesRead != Size) {
- return EFAULT;
- }
- return 0;
- }
- INT
- DwarfTargetReadRegister (
- PDWARF_CONTEXT Context,
- ULONG Register,
- PULONGLONG Value
- )
- /*++
- Routine Description:
- This routine reads a register value.
- Arguments:
- Context - Supplies a pointer to the DWARF context.
- Register - Supplies the register to read.
- Value - Supplies a pointer where the value will be returned on success.
- Return Value:
- 0 on success.
- Returns an error number on failure.
- --*/
- {
- PDEBUGGER_CONTEXT DebuggerContext;
- PREGISTERS_UNION Registers;
- INT Status;
- PDEBUG_SYMBOLS Symbols;
- Symbols = (((PDEBUG_SYMBOLS)Context) - 1);
- DebuggerContext = Symbols->HostContext;
- assert(DebuggerContext != NULL);
- Registers = Symbols->RegistersContext;
- if (Registers == NULL) {
- Registers = &(DebuggerContext->FrameRegisters);
- }
- Status = DbgGetRegister(DebuggerContext, Registers, Register, Value);
- return Status;
- }
- INT
- DwarfTargetWriteRegister (
- PDWARF_CONTEXT Context,
- ULONG Register,
- ULONGLONG Value
- )
- /*++
- Routine Description:
- This routine writes a register value.
- Arguments:
- Context - Supplies a pointer to the DWARF context.
- Register - Supplies the register to write.
- Value - Supplies the new value of the register.
- Return Value:
- 0 on success.
- Returns an error number on failure.
- --*/
- {
- PDEBUGGER_CONTEXT DebuggerContext;
- PREGISTERS_UNION Registers;
- INT Status;
- PDEBUG_SYMBOLS Symbols;
- Symbols = (((PDEBUG_SYMBOLS)Context) - 1);
- DebuggerContext = Symbols->HostContext;
- assert(DebuggerContext != NULL);
- Registers = Symbols->RegistersContext;
- if (Registers == NULL) {
- Registers = &(DebuggerContext->FrameRegisters);
- }
- Status = DbgSetRegister(DebuggerContext, Registers, Register, Value);
- return Status;
- }
- INT
- DwarfTargetWritePc (
- PDWARF_CONTEXT Context,
- ULONGLONG Value
- )
- /*++
- Routine Description:
- This routine writes a the instruction pointer register, presumably with the
- return address.
- Arguments:
- Context - Supplies a pointer to the DWARF context.
- Value - Supplies the new value of the register.
- Return Value:
- 0 on success.
- Returns an error number on failure.
- --*/
- {
- PDEBUGGER_CONTEXT DebuggerContext;
- PREGISTERS_UNION Registers;
- PDEBUG_SYMBOLS Symbols;
- Symbols = (((PDEBUG_SYMBOLS)Context) - 1);
- DebuggerContext = Symbols->HostContext;
- assert(DebuggerContext != NULL);
- Registers = Symbols->RegistersContext;
- if (Registers == NULL) {
- Registers = &(DebuggerContext->FrameRegisters);
- }
- DbgSetPc(DebuggerContext, Registers, Value);
- return 0;
- }
- PSTR
- DwarfGetRegisterName (
- PDWARF_CONTEXT Context,
- ULONG Register
- )
- /*++
- Routine Description:
- This routine returns a string containing the name of the given register.
- Arguments:
- Context - Supplies a pointer to the application context.
- Register - Supplies the register number.
- Return Value:
- Returns a pointer to a constant string containing the name of the register.
- --*/
- {
- PDEBUG_SYMBOLS Symbols;
- Symbols = (((PDEBUG_SYMBOLS)Context) - 1);
- return DbgGetRegisterName(Symbols->Machine, Register);
- }
- ULONG
- DwarfGetNativeSize (
- PDWARF_CONTEXT Context
- )
- /*++
- Routine Description:
- This routine returns the native machine word size.
- Arguments:
- Context - Supplies a pointer to the application context.
- Return Value:
- Returns the number of bytes in a machine word: usually 4 for 32-bit
- machines and 8 for 64-bit machines.
- --*/
- {
- PDEBUG_SYMBOLS Symbols;
- Symbols = (((PDEBUG_SYMBOLS)Context) - 1);
- switch (Symbols->Machine) {
- case ImageMachineTypeX86:
- case ImageMachineTypeArm32:
- return 4;
- case ImageMachineTypeX64:
- case ImageMachineTypeArm64:
- return 8;
- default:
- assert(FALSE);
- break;
- }
- return 0;
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
|