123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- /*++
- Copyright (c) 2015 Minoca Corp. All Rights Reserved
- 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;
- }
- 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);
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
|