2013-01-25 12:28:06 +01:00
|
|
|
|
/** @file
|
|
|
|
|
UEFI driver that implements a GDB stub
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Note: Any code in the path of the Serial IO output can not call DEBUG as will
|
|
|
|
|
will blow out the stack. Serial IO calls DEBUG, debug calls Serail IO, ...
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
This program and the accompanying materials
|
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
#include <GdbStubInternal.h>
|
|
|
|
|
#include <Protocol/DebugPort.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UINTN gMaxProcessorIndex = 0;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Buffers for basic gdb communication
|
|
|
|
|
//
|
|
|
|
|
CHAR8 gInBuffer[MAX_BUF_SIZE];
|
|
|
|
|
CHAR8 gOutBuffer[MAX_BUF_SIZE];
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
// Assume gdb does a "qXfer:libraries:read::offset,length" when it connects so we can default
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// this value to FALSE. Since gdb can reconnect its self a global default is not good enough
|
|
|
|
|
BOOLEAN gSymbolTableUpdate = FALSE;
|
|
|
|
|
EFI_EVENT gEvent;
|
|
|
|
|
VOID *gGdbSymbolEventHandlerRegistration = NULL;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Globals for returning XML from qXfer:libraries:read packet
|
|
|
|
|
//
|
|
|
|
|
UINTN gPacketqXferLibraryOffset = 0;
|
|
|
|
|
UINTN gEfiDebugImageTableEntry = 0;
|
|
|
|
|
EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader = NULL;
|
|
|
|
|
EFI_DEBUG_IMAGE_INFO *gDebugTable = NULL;
|
|
|
|
|
CHAR8 gXferLibraryBuffer[2000];
|
|
|
|
|
|
|
|
|
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexToStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
|
|
|
|
GdbSymbolEventHandler (
|
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
|
IN VOID *Context
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
The user Entry Point for Application. The user code starts with this function
|
2014-08-19 15:29:52 +02:00
|
|
|
|
as the real entry point for the image goes into a library that calls this
|
2013-01-25 12:28:06 +01:00
|
|
|
|
function.
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@param[in] ImageHandle The firmware allocated handle for the EFI image.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param[in] SystemTable A pointer to the EFI System Table.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@retval EFI_SUCCESS The entry point is executed successfully.
|
|
|
|
|
@retval other Some error occurs when executing this entry point.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
EFI_STATUS
|
|
|
|
|
EFIAPI
|
|
|
|
|
GdbStubEntry (
|
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
|
)
|
|
|
|
|
{
|
2014-08-19 15:29:52 +02:00
|
|
|
|
EFI_STATUS Status;
|
2013-01-25 12:28:06 +01:00
|
|
|
|
EFI_DEBUG_SUPPORT_PROTOCOL *DebugSupport;
|
|
|
|
|
UINTN HandleCount;
|
|
|
|
|
EFI_HANDLE *Handles;
|
|
|
|
|
UINTN Index;
|
|
|
|
|
UINTN Processor;
|
|
|
|
|
BOOLEAN IsaSupported;
|
2013-03-12 01:45:29 +01:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&gDebugImageTableHeader);
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
|
gDebugImageTableHeader = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
|
ByProtocol,
|
|
|
|
|
&gEfiDebugSupportProtocolGuid,
|
|
|
|
|
NULL,
|
|
|
|
|
&HandleCount,
|
|
|
|
|
&Handles
|
|
|
|
|
);
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
|
DEBUG ((EFI_D_ERROR, "Debug Support Protocol not found\n"));
|
|
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
DebugSupport = NULL;
|
|
|
|
|
IsaSupported = FALSE;
|
|
|
|
|
do {
|
|
|
|
|
HandleCount--;
|
|
|
|
|
Status = gBS->HandleProtocol (
|
|
|
|
|
Handles[HandleCount],
|
|
|
|
|
&gEfiDebugSupportProtocolGuid,
|
|
|
|
|
(VOID **) &DebugSupport
|
|
|
|
|
);
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
|
if (CheckIsa (DebugSupport->Isa)) {
|
|
|
|
|
// We found what we are looking for so break out of the loop
|
|
|
|
|
IsaSupported = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (HandleCount > 0);
|
|
|
|
|
FreePool (Handles);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
if (!IsaSupported) {
|
|
|
|
|
DEBUG ((EFI_D_ERROR, "Debug Support Protocol does not support our ISA\n"));
|
|
|
|
|
|
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Status = DebugSupport->GetMaximumProcessorIndex (DebugSupport, &gMaxProcessorIndex);
|
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
DEBUG ((EFI_D_INFO, "Debug Support Protocol ISA %x\n", DebugSupport->Isa));
|
|
|
|
|
DEBUG ((EFI_D_INFO, "Debug Support Protocol Processor Index %d\n", gMaxProcessorIndex));
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// Call processor-specific init routine
|
2013-03-12 01:45:29 +01:00
|
|
|
|
InitializeProcessor ();
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
for (Processor = 0; Processor <= gMaxProcessorIndex; Processor++) {
|
|
|
|
|
for (Index = 0; Index < MaxEfiException (); Index++) {
|
|
|
|
|
Status = DebugSupport->RegisterExceptionCallback (DebugSupport, Processor, GdbExceptionHandler, gExceptionType[Index].Exception);
|
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
// Current edk2 DebugPort is not interrupt context safe so we can not use it
|
|
|
|
|
//
|
|
|
|
|
Status = DebugSupport->RegisterPeriodicCallback (DebugSupport, Processor, GdbPeriodicCallBack);
|
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//
|
|
|
|
|
// This even fires every time an image is added. This allows the stub to know when gdb needs
|
2014-08-19 15:29:52 +02:00
|
|
|
|
// to update the symbol table.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//
|
|
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
|
TPL_CALLBACK,
|
|
|
|
|
GdbSymbolEventHandler,
|
|
|
|
|
NULL,
|
|
|
|
|
&gEvent
|
|
|
|
|
);
|
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
|
|
//
|
2013-03-12 01:45:29 +01:00
|
|
|
|
// Register for protocol notifications on this event
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//
|
|
|
|
|
Status = gBS->RegisterProtocolNotify (
|
|
|
|
|
&gEfiLoadedImageProtocolGuid,
|
|
|
|
|
gEvent,
|
|
|
|
|
&gGdbSymbolEventHandlerRegistration
|
|
|
|
|
);
|
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
if (PcdGetBool (PcdGdbSerial)) {
|
|
|
|
|
GdbInitializeSerialConsole ();
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Transfer length bytes of input buffer, starting at Address, to memory.
|
|
|
|
|
|
|
|
|
|
@param length the number of the bytes to be transferred/written
|
|
|
|
|
@param *address the start address of the transferring/writing the memory
|
|
|
|
|
@param *new_data the new data to be written to memory
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
TransferFromInBufToMem (
|
|
|
|
|
IN UINTN Length,
|
|
|
|
|
IN unsigned char *Address,
|
|
|
|
|
IN CHAR8 *NewData
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
CHAR8 c1;
|
|
|
|
|
CHAR8 c2;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
while (Length-- > 0) {
|
|
|
|
|
c1 = (CHAR8)HexCharToInt (*NewData++);
|
|
|
|
|
c2 = (CHAR8)HexCharToInt (*NewData++);
|
|
|
|
|
|
|
|
|
|
if ((c1 < 0) || (c2 < 0)) {
|
|
|
|
|
Print ((CHAR16 *)L"Bad message from write to memory..\n");
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendError (GDB_EBADMEMDATA);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
*Address++ = (UINT8)((c1 << 4) + c2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendSuccess();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Transfer Length bytes of memory starting at Address to an output buffer, OutBuffer. This function will finally send the buffer
|
|
|
|
|
as a packet.
|
|
|
|
|
|
|
|
|
|
@param Length the number of the bytes to be transferred/read
|
|
|
|
|
@param *address pointer to the start address of the transferring/reading the memory
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
TransferFromMemToOutBufAndSend (
|
|
|
|
|
IN UINTN Length,
|
|
|
|
|
IN unsigned char *Address
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
// there are Length bytes and every byte is represented as 2 hex chars
|
|
|
|
|
CHAR8 OutBuffer[MAX_BUF_SIZE];
|
|
|
|
|
CHAR8 *OutBufPtr; // pointer to the output buffer
|
|
|
|
|
CHAR8 Char;
|
|
|
|
|
|
|
|
|
|
if (ValidateAddress(Address) == FALSE) {
|
|
|
|
|
SendError(14);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutBufPtr = OutBuffer;
|
|
|
|
|
while (Length > 0) {
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Char = mHexToStr[*Address >> 4];
|
|
|
|
|
if ((Char >= 'A') && (Char <= 'F')) {
|
|
|
|
|
Char = Char - 'A' + 'a';
|
|
|
|
|
}
|
|
|
|
|
*OutBufPtr++ = Char;
|
|
|
|
|
|
|
|
|
|
Char = mHexToStr[*Address & 0x0f];
|
|
|
|
|
if ((Char >= 'A') && (Char <= 'F')) {
|
|
|
|
|
Char = Char - 'A' + 'a';
|
|
|
|
|
}
|
|
|
|
|
*OutBufPtr++ = Char;
|
|
|
|
|
|
|
|
|
|
Address++;
|
|
|
|
|
Length--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*OutBufPtr = '\0' ; // the end of the buffer
|
|
|
|
|
SendPacket (OutBuffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Send a GDB Remote Serial Protocol Packet
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
$PacketData#checksum PacketData is passed in and this function adds the packet prefix '$',
|
2013-01-25 12:28:06 +01:00
|
|
|
|
the packet teminating character '#' and the two digit checksum.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up
|
2013-01-25 12:28:06 +01:00
|
|
|
|
in an infinit loop. This is so if you unplug the debugger code just keeps running
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@param PacketData Payload data for the packet
|
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
@retval Number of bytes of packet data sent.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
UINTN
|
|
|
|
|
SendPacket (
|
|
|
|
|
IN CHAR8 *PacketData
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINT8 CheckSum;
|
|
|
|
|
UINTN Timeout;
|
|
|
|
|
CHAR8 *Ptr;
|
|
|
|
|
CHAR8 TestChar;
|
|
|
|
|
UINTN Count;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Timeout = PcdGet32 (PcdGdbMaxPacketRetryCount);
|
|
|
|
|
|
|
|
|
|
Count = 0;
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
|
|
Ptr = PacketData;
|
|
|
|
|
|
|
|
|
|
if (Timeout-- == 0) {
|
|
|
|
|
// Only try a finite number of times so we don't get stuck in the loop
|
|
|
|
|
return Count;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// Packet prefix
|
|
|
|
|
GdbPutChar ('$');
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
for (CheckSum = 0, Count =0 ; *Ptr != '\0'; Ptr++, Count++) {
|
|
|
|
|
GdbPutChar (*Ptr);
|
|
|
|
|
CheckSum = CheckSum + *Ptr;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
// Packet terminating character and checksum
|
2013-01-25 12:28:06 +01:00
|
|
|
|
GdbPutChar ('#');
|
|
|
|
|
GdbPutChar (mHexToStr[CheckSum >> 4]);
|
|
|
|
|
GdbPutChar (mHexToStr[CheckSum & 0x0F]);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
TestChar = GdbGetChar ();
|
|
|
|
|
} while (TestChar != '+');
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Receive a GDB Remote Serial Protocol Packet
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
$PacketData#checksum PacketData is passed in and this function adds the packet prefix '$',
|
2013-01-25 12:28:06 +01:00
|
|
|
|
the packet teminating character '#' and the two digit checksum.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2016-10-19 09:01:14 +02:00
|
|
|
|
If host re-starts sending a packet without ending the previous packet, only the last valid packet is processed.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
(In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.)
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
If an ack '+' is not sent resend the packet
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@param PacketData Payload data for the packet
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
@retval Number of bytes of packet data received.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
UINTN
|
|
|
|
|
ReceivePacket (
|
|
|
|
|
OUT CHAR8 *PacketData,
|
|
|
|
|
IN UINTN PacketDataSize
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINT8 CheckSum;
|
|
|
|
|
UINTN Index;
|
|
|
|
|
CHAR8 Char;
|
|
|
|
|
CHAR8 SumString[3];
|
|
|
|
|
CHAR8 TestChar;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
ZeroMem (PacketData, PacketDataSize);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
for (;;) {
|
|
|
|
|
// wait for the start of a packet
|
|
|
|
|
TestChar = GdbGetChar ();
|
|
|
|
|
while (TestChar != '$') {
|
|
|
|
|
TestChar = GdbGetChar ();
|
|
|
|
|
};
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
retry:
|
|
|
|
|
for (Index = 0, CheckSum = 0; Index < (PacketDataSize - 1); Index++) {
|
|
|
|
|
Char = GdbGetChar ();
|
|
|
|
|
if (Char == '$') {
|
|
|
|
|
goto retry;
|
|
|
|
|
}
|
|
|
|
|
if (Char == '#') {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PacketData[Index] = Char;
|
|
|
|
|
CheckSum = CheckSum + Char;
|
|
|
|
|
}
|
|
|
|
|
PacketData[Index] = '\0';
|
|
|
|
|
|
|
|
|
|
if (Index == PacketDataSize) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SumString[0] = GdbGetChar ();
|
2013-01-25 12:28:06 +01:00
|
|
|
|
SumString[1] = GdbGetChar ();
|
|
|
|
|
SumString[2] = '\0';
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
if (AsciiStrHexToUintn (SumString) == CheckSum) {
|
|
|
|
|
// Ack: Success
|
|
|
|
|
GdbPutChar ('+');
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// Null terminate the callers string
|
|
|
|
|
PacketData[Index] = '\0';
|
|
|
|
|
return Index;
|
|
|
|
|
} else {
|
|
|
|
|
// Ack: Failure
|
|
|
|
|
GdbPutChar ('-');
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Empties the given buffer
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param Buf pointer to the first element in buffer to be emptied
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
2014-08-19 15:29:52 +02:00
|
|
|
|
EmptyBuffer (
|
2013-01-25 12:28:06 +01:00
|
|
|
|
IN CHAR8 *Buf
|
|
|
|
|
)
|
2014-08-19 15:29:52 +02:00
|
|
|
|
{
|
2013-01-25 12:28:06 +01:00
|
|
|
|
*Buf = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Converts an 8-bit Hex Char into a INTN.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param Char the hex character to be converted into UINTN
|
|
|
|
|
@retval a INTN, from 0 to 15, that corressponds to Char
|
|
|
|
|
-1 if Char is not a hex character
|
|
|
|
|
**/
|
|
|
|
|
INTN
|
|
|
|
|
HexCharToInt (
|
|
|
|
|
IN CHAR8 Char
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
if ((Char >= 'A') && (Char <= 'F')) {
|
|
|
|
|
return Char - 'A' + 10;
|
|
|
|
|
} else if ((Char >= 'a') && (Char <= 'f')) {
|
|
|
|
|
return Char - 'a' + 10;
|
|
|
|
|
} else if ((Char >= '0') && (Char <= '9')) {
|
|
|
|
|
return Char - '0';
|
|
|
|
|
} else { // if not a hex value, return a negative value
|
2014-08-19 15:29:52 +02:00
|
|
|
|
return -1;
|
2013-01-25 12:28:06 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 'E' + the biggest error number is 255, so its 2 hex digits + buffer end
|
|
|
|
|
CHAR8 *gError = "E__";
|
|
|
|
|
|
|
|
|
|
/** 'E NN'
|
|
|
|
|
Send an error with the given error number after converting to hex.
|
|
|
|
|
The error number is put into the buffer in hex. '255' is the biggest errno we can send.
|
|
|
|
|
ex: 162 will be sent as A2.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param errno the error number that will be sent
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
|
|
|
|
SendError (
|
|
|
|
|
IN UINT8 ErrorNum
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// Replace _, or old data, with current errno
|
|
|
|
|
//
|
|
|
|
|
gError[1] = mHexToStr [ErrorNum >> 4];
|
|
|
|
|
gError[2] = mHexToStr [ErrorNum & 0x0f];
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
SendPacket (gError); // send buffer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Send 'OK' when the function is done executing successfully.
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
|
|
|
|
SendSuccess (
|
|
|
|
|
VOID
|
2014-08-19 15:29:52 +02:00
|
|
|
|
)
|
2013-01-25 12:28:06 +01:00
|
|
|
|
{
|
|
|
|
|
SendPacket ("OK"); // send buffer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Send empty packet to specify that particular command/functionality is not supported.
|
|
|
|
|
**/
|
2014-08-19 15:29:52 +02:00
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
2013-01-25 12:28:06 +01:00
|
|
|
|
SendNotSupported (
|
2014-08-19 15:29:52 +02:00
|
|
|
|
VOID
|
|
|
|
|
)
|
2013-03-12 01:45:29 +01:00
|
|
|
|
{
|
2013-01-25 12:28:06 +01:00
|
|
|
|
SendPacket ("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
@param GdbExceptionType GDB exception type
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
GdbSendTSignal (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN UINT8 GdbExceptionType
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
CHAR8 TSignalBuffer[128];
|
|
|
|
|
CHAR8 *TSignalPtr;
|
|
|
|
|
UINTN BreakpointDetected;
|
|
|
|
|
BREAK_TYPE BreakType;
|
|
|
|
|
UINTN DataAddress;
|
|
|
|
|
CHAR8 *WatchStrPtr = NULL;
|
|
|
|
|
UINTN RegSize;
|
|
|
|
|
|
|
|
|
|
TSignalPtr = &TSignalBuffer[0];
|
|
|
|
|
|
|
|
|
|
//Construct TSignal packet
|
|
|
|
|
*TSignalPtr++ = 'T';
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// replace _, or previous value, with Exception type
|
|
|
|
|
//
|
2014-08-19 15:29:52 +02:00
|
|
|
|
*TSignalPtr++ = mHexToStr [GdbExceptionType >> 4];
|
2013-01-25 12:28:06 +01:00
|
|
|
|
*TSignalPtr++ = mHexToStr [GdbExceptionType & 0x0f];
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
if (GdbExceptionType == GDB_SIGTRAP) {
|
|
|
|
|
if (gSymbolTableUpdate) {
|
|
|
|
|
//
|
|
|
|
|
// We can only send back on reason code. So if the flag is set it means the breakpoint is from our event handler
|
|
|
|
|
//
|
|
|
|
|
WatchStrPtr = "library:;";
|
|
|
|
|
while (*WatchStrPtr != '\0') {
|
|
|
|
|
*TSignalPtr++ = *WatchStrPtr++;
|
|
|
|
|
}
|
|
|
|
|
gSymbolTableUpdate = FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// possible n:r pairs
|
2014-08-19 15:29:52 +02:00
|
|
|
|
//
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
//Retrieve the breakpoint number
|
|
|
|
|
BreakpointDetected = GetBreakpointDetected (SystemContext);
|
|
|
|
|
|
|
|
|
|
//Figure out if the exception is happend due to watch, rwatch or awatch.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
BreakType = GetBreakpointType (SystemContext, BreakpointDetected);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
//INFO: rwatch is not supported due to the way IA32 debug registers work
|
|
|
|
|
if ((BreakType == DataWrite) || (BreakType == DataRead) || (BreakType == DataReadWrite)) {
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//Construct n:r pair
|
|
|
|
|
DataAddress = GetBreakpointDataAddress (SystemContext, BreakpointDetected);
|
|
|
|
|
|
|
|
|
|
//Assign appropriate buffer to print particular watchpoint type
|
|
|
|
|
if (BreakType == DataWrite) {
|
|
|
|
|
WatchStrPtr = "watch";
|
|
|
|
|
} else if (BreakType == DataRead) {
|
|
|
|
|
WatchStrPtr = "rwatch";
|
|
|
|
|
} else if (BreakType == DataReadWrite) {
|
|
|
|
|
WatchStrPtr = "awatch";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (*WatchStrPtr != '\0') {
|
|
|
|
|
*TSignalPtr++ = *WatchStrPtr++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*TSignalPtr++ = ':';
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//Set up series of bytes in big-endian byte order. "awatch" won't work with little-endian byte order.
|
|
|
|
|
RegSize = REG_SIZE;
|
|
|
|
|
while (RegSize > 0) {
|
|
|
|
|
RegSize = RegSize-4;
|
|
|
|
|
*TSignalPtr++ = mHexToStr[(UINT8)(DataAddress >> RegSize) & 0xf];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Always end n:r pair with ';'
|
|
|
|
|
*TSignalPtr++ = ';';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*TSignalPtr = '\0';
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendPacket (TSignalBuffer);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Translates the EFI mapping to GDB mapping
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param EFIExceptionType EFI Exception that is being processed
|
|
|
|
|
@retval UINTN that corresponds to EFIExceptionType's GDB exception type number
|
|
|
|
|
**/
|
|
|
|
|
UINT8
|
2014-08-19 15:29:52 +02:00
|
|
|
|
ConvertEFItoGDBtype (
|
2013-01-25 12:28:06 +01:00
|
|
|
|
IN EFI_EXCEPTION_TYPE EFIExceptionType
|
|
|
|
|
)
|
2014-08-19 15:29:52 +02:00
|
|
|
|
{
|
2013-03-12 01:45:29 +01:00
|
|
|
|
UINTN Index;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
for (Index = 0; Index < MaxEfiException () ; Index++) {
|
|
|
|
|
if (gExceptionType[Index].Exception == EFIExceptionType) {
|
|
|
|
|
return gExceptionType[Index].SignalNo;
|
2013-01-25 12:28:06 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return GDB_SIGTRAP; // this is a GDB trap
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** "m addr,length"
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Find the Length of the area to read and the start addres. Finally, pass them to
|
|
|
|
|
another function, TransferFromMemToOutBufAndSend, that will read from that memory space and
|
2013-01-25 12:28:06 +01:00
|
|
|
|
send it as a packet.
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
|
|
|
|
ReadFromMemory (
|
|
|
|
|
CHAR8 *PacketData
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINTN Address;
|
|
|
|
|
UINTN Length;
|
|
|
|
|
CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the address in hex chars
|
|
|
|
|
CHAR8 *AddrBufPtr; // pointer to the address buffer
|
|
|
|
|
CHAR8 *InBufPtr; /// pointer to the input buffer
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
AddrBufPtr = AddressBuffer;
|
|
|
|
|
InBufPtr = &PacketData[1];
|
|
|
|
|
while (*InBufPtr != ',') {
|
|
|
|
|
*AddrBufPtr++ = *InBufPtr++;
|
|
|
|
|
}
|
|
|
|
|
*AddrBufPtr = '\0';
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
InBufPtr++; // this skips ',' in the buffer
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
/* Error checking */
|
2013-03-12 01:45:29 +01:00
|
|
|
|
if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Print((CHAR16 *)L"Address is too long\n");
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendError (GDB_EBADMEMADDRBUFSIZE);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// 2 = 'm' + ','
|
2013-03-12 01:45:29 +01:00
|
|
|
|
if (AsciiStrLen (PacketData) - AsciiStrLen (AddressBuffer) - 2 >= MAX_LENGTH_SIZE) {
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Print((CHAR16 *)L"Length is too long\n");
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendError (GDB_EBADMEMLENGTH);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Address = AsciiStrHexToUintn (AddressBuffer);
|
|
|
|
|
Length = AsciiStrHexToUintn (InBufPtr);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
TransferFromMemToOutBufAndSend (Length, (unsigned char *)Address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** "M addr,length :XX..."
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Find the Length of the area in bytes to write and the start addres. Finally, pass them to
|
2013-01-25 12:28:06 +01:00
|
|
|
|
another function, TransferFromInBufToMem, that will write to that memory space the info in
|
|
|
|
|
the input buffer.
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
|
|
|
|
WriteToMemory (
|
|
|
|
|
IN CHAR8 *PacketData
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINTN Address;
|
|
|
|
|
UINTN Length;
|
|
|
|
|
UINTN MessageLength;
|
|
|
|
|
CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the Address in hex chars
|
|
|
|
|
CHAR8 LengthBuffer[MAX_LENGTH_SIZE]; // the buffer that will hold the Length in hex chars
|
|
|
|
|
CHAR8 *AddrBufPtr; // pointer to the Address buffer
|
|
|
|
|
CHAR8 *LengthBufPtr; // pointer to the Length buffer
|
|
|
|
|
CHAR8 *InBufPtr; /// pointer to the input buffer
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
AddrBufPtr = AddressBuffer;
|
|
|
|
|
LengthBufPtr = LengthBuffer;
|
|
|
|
|
InBufPtr = &PacketData[1];
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
while (*InBufPtr != ',') {
|
|
|
|
|
*AddrBufPtr++ = *InBufPtr++;
|
|
|
|
|
}
|
|
|
|
|
*AddrBufPtr = '\0';
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
InBufPtr++; // this skips ',' in the buffer
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
while (*InBufPtr != ':') {
|
|
|
|
|
*LengthBufPtr++ = *InBufPtr++;
|
|
|
|
|
}
|
|
|
|
|
*LengthBufPtr = '\0';
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
InBufPtr++; // this skips ':' in the buffer
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Address = AsciiStrHexToUintn (AddressBuffer);
|
|
|
|
|
Length = AsciiStrHexToUintn (LengthBuffer);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
/* Error checking */
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//Check if Address is not too long.
|
2013-03-12 01:45:29 +01:00
|
|
|
|
if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Print ((CHAR16 *)L"Address too long..\n");
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendError (GDB_EBADMEMADDRBUFSIZE);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//Check if message length is not too long
|
2013-03-12 01:45:29 +01:00
|
|
|
|
if (AsciiStrLen (LengthBuffer) >= MAX_LENGTH_SIZE) {
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Print ((CHAR16 *)L"Length too long..\n");
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendError (GDB_EBADMEMLENGBUFSIZE);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// Check if Message is not too long/short.
|
|
|
|
|
// 3 = 'M' + ',' + ':'
|
2013-03-12 01:45:29 +01:00
|
|
|
|
MessageLength = (AsciiStrLen (PacketData) - AsciiStrLen (AddressBuffer) - AsciiStrLen (LengthBuffer) - 3);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
if (MessageLength != (2*Length)) {
|
|
|
|
|
//Message too long/short. New data is not the right size.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendError (GDB_EBADMEMDATASIZE);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TransferFromInBufToMem (Length, (unsigned char *)Address, InBufPtr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Parses breakpoint packet data and captures Breakpoint type, Address and length.
|
|
|
|
|
In case of an error, function returns particular error code. Returning 0 meaning
|
|
|
|
|
no error.
|
|
|
|
|
|
|
|
|
|
@param PacketData Pointer to the payload data for the packet.
|
|
|
|
|
@param Type Breakpoint type
|
|
|
|
|
@param Address Breakpoint address
|
|
|
|
|
@param Length Breakpoint length in Bytes (1 byte, 2 byte, 4 byte)
|
|
|
|
|
|
|
|
|
|
@retval 1 Success
|
|
|
|
|
@retval {other} Particular error code
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
UINTN
|
|
|
|
|
ParseBreakpointPacket (
|
|
|
|
|
IN CHAR8 *PacketData,
|
|
|
|
|
OUT UINTN *Type,
|
|
|
|
|
OUT UINTN *Address,
|
|
|
|
|
OUT UINTN *Length
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
CHAR8 AddressBuffer[MAX_ADDR_SIZE];
|
|
|
|
|
CHAR8 *AddressBufferPtr;
|
|
|
|
|
CHAR8 *PacketDataPtr;
|
|
|
|
|
|
|
|
|
|
PacketDataPtr = &PacketData[1];
|
|
|
|
|
AddressBufferPtr = AddressBuffer;
|
|
|
|
|
|
|
|
|
|
*Type = AsciiStrHexToUintn (PacketDataPtr);
|
|
|
|
|
|
|
|
|
|
//Breakpoint/watchpoint type should be between 0 to 4
|
|
|
|
|
if (*Type > 4) {
|
|
|
|
|
Print ((CHAR16 *)L"Type is invalid\n");
|
|
|
|
|
return 22; //EINVAL: Invalid argument.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Skip ',' in the buffer.
|
|
|
|
|
while (*PacketDataPtr++ != ',');
|
|
|
|
|
|
|
|
|
|
//Parse Address information
|
|
|
|
|
while (*PacketDataPtr != ',') {
|
|
|
|
|
*AddressBufferPtr++ = *PacketDataPtr++;
|
|
|
|
|
}
|
|
|
|
|
*AddressBufferPtr = '\0';
|
|
|
|
|
|
|
|
|
|
//Check if Address is not too long.
|
2013-03-12 01:45:29 +01:00
|
|
|
|
if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Print ((CHAR16 *)L"Address too long..\n");
|
|
|
|
|
return 40; //EMSGSIZE: Message size too long.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*Address = AsciiStrHexToUintn (AddressBuffer);
|
|
|
|
|
|
|
|
|
|
PacketDataPtr++; //This skips , in the buffer
|
|
|
|
|
|
|
|
|
|
//Parse Length information
|
|
|
|
|
*Length = AsciiStrHexToUintn (PacketDataPtr);
|
|
|
|
|
|
|
|
|
|
//Length should be 1, 2 or 4 bytes
|
|
|
|
|
if (*Length > 4) {
|
|
|
|
|
Print ((CHAR16 *)L"Length is invalid\n");
|
|
|
|
|
return 22; //EINVAL: Invalid argument
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0; //0 = No error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINTN
|
|
|
|
|
gXferObjectReadResponse (
|
|
|
|
|
IN CHAR8 Type,
|
|
|
|
|
IN CHAR8 *Str
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
CHAR8 *OutBufPtr; // pointer to the output buffer
|
|
|
|
|
CHAR8 Char;
|
|
|
|
|
UINTN Count;
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
// Response starts with 'm' or 'l' if it is the end
|
2013-01-25 12:28:06 +01:00
|
|
|
|
OutBufPtr = gOutBuffer;
|
|
|
|
|
*OutBufPtr++ = Type;
|
|
|
|
|
Count = 1;
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
// Binary data encoding
|
2013-01-25 12:28:06 +01:00
|
|
|
|
OutBufPtr = gOutBuffer;
|
|
|
|
|
while (*Str != '\0') {
|
|
|
|
|
Char = *Str++;
|
|
|
|
|
if ((Char == 0x7d) || (Char == 0x23) || (Char == 0x24) || (Char == 0x2a)) {
|
|
|
|
|
// escape character
|
|
|
|
|
*OutBufPtr++ = 0x7d;
|
|
|
|
|
|
|
|
|
|
Char ^= 0x20;
|
|
|
|
|
}
|
|
|
|
|
*OutBufPtr++ = Char;
|
|
|
|
|
Count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*OutBufPtr = '\0' ; // the end of the buffer
|
|
|
|
|
SendPacket (gOutBuffer);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Note: This should be a library function. In the Apple case you have to add
|
|
|
|
|
the size of the PE/COFF header into the starting address to make things work
|
2013-01-25 12:28:06 +01:00
|
|
|
|
right as there is no way to pad the Mach-O for the size of the PE/COFF header.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Returns a pointer to the PDB file name for a PE/COFF image that has been
|
|
|
|
|
loaded into system memory with the PE/COFF Loader Library functions.
|
|
|
|
|
|
|
|
|
|
Returns the PDB file name for the PE/COFF image specified by Pe32Data. If
|
|
|
|
|
the PE/COFF image specified by Pe32Data is not a valid, then NULL is
|
|
|
|
|
returned. If the PE/COFF image specified by Pe32Data does not contain a
|
|
|
|
|
debug directory entry, then NULL is returned. If the debug directory entry
|
|
|
|
|
in the PE/COFF image specified by Pe32Data does not contain a PDB file name,
|
|
|
|
|
then NULL is returned.
|
|
|
|
|
If Pe32Data is NULL, then ASSERT().
|
|
|
|
|
|
|
|
|
|
@param Pe32Data Pointer to the PE/COFF image that is loaded in system
|
|
|
|
|
memory.
|
|
|
|
|
@param DebugBase Address that the debugger would use as the base of the image
|
|
|
|
|
|
|
|
|
|
@return The PDB file name for the PE/COFF image specified by Pe32Data or NULL
|
|
|
|
|
if it cannot be retrieved. DebugBase is only valid if PDB file name is
|
2014-08-19 15:29:52 +02:00
|
|
|
|
valid.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
VOID *
|
|
|
|
|
EFIAPI
|
|
|
|
|
PeCoffLoaderGetDebuggerInfo (
|
|
|
|
|
IN VOID *Pe32Data,
|
|
|
|
|
OUT VOID **DebugBase
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
EFI_IMAGE_DOS_HEADER *DosHdr;
|
|
|
|
|
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
|
|
|
|
|
EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
|
|
|
|
|
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;
|
|
|
|
|
UINTN DirCount;
|
|
|
|
|
VOID *CodeViewEntryPointer;
|
|
|
|
|
INTN TEImageAdjust;
|
|
|
|
|
UINT32 NumberOfRvaAndSizes;
|
|
|
|
|
UINT16 Magic;
|
|
|
|
|
UINTN SizeOfHeaders;
|
|
|
|
|
|
|
|
|
|
ASSERT (Pe32Data != NULL);
|
|
|
|
|
|
|
|
|
|
TEImageAdjust = 0;
|
|
|
|
|
DirectoryEntry = NULL;
|
|
|
|
|
DebugEntry = NULL;
|
|
|
|
|
NumberOfRvaAndSizes = 0;
|
|
|
|
|
SizeOfHeaders = 0;
|
|
|
|
|
|
|
|
|
|
DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
|
|
|
|
|
if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
|
|
|
|
|
//
|
|
|
|
|
// DOS image header is present, so read the PE header after the DOS image header.
|
|
|
|
|
//
|
|
|
|
|
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
|
|
|
|
|
} else {
|
|
|
|
|
//
|
|
|
|
|
// DOS image header is not present, so PE header is at the image base.
|
|
|
|
|
//
|
|
|
|
|
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
|
|
|
|
|
if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {
|
|
|
|
|
DirectoryEntry = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];
|
|
|
|
|
TEImageAdjust = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;
|
|
|
|
|
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +
|
|
|
|
|
Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +
|
|
|
|
|
TEImageAdjust);
|
|
|
|
|
}
|
|
|
|
|
SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// __APPLE__ check this math...
|
|
|
|
|
*DebugBase = ((CHAR8 *)Pe32Data) - TEImageAdjust;
|
|
|
|
|
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
*DebugBase = Pe32Data;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//
|
|
|
|
|
// NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.
|
|
|
|
|
// It is due to backward-compatibility, for some system might
|
|
|
|
|
// generate PE32+ image with PE32 Magic.
|
|
|
|
|
//
|
|
|
|
|
switch (Hdr.Pe32->FileHeader.Machine) {
|
|
|
|
|
case EFI_IMAGE_MACHINE_IA32:
|
|
|
|
|
//
|
|
|
|
|
// Assume PE32 image with IA32 Machine field.
|
|
|
|
|
//
|
|
|
|
|
Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
|
|
|
|
|
break;
|
|
|
|
|
case EFI_IMAGE_MACHINE_X64:
|
|
|
|
|
case EFI_IMAGE_MACHINE_IA64:
|
|
|
|
|
//
|
|
|
|
|
// Assume PE32+ image with X64 or IPF Machine field
|
|
|
|
|
//
|
|
|
|
|
Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
//
|
|
|
|
|
// For unknow Machine field, use Magic in optional Header
|
|
|
|
|
//
|
|
|
|
|
Magic = Hdr.Pe32->OptionalHeader.Magic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
|
|
|
|
|
//
|
|
|
|
|
// Use PE32 offset get Debug Directory Entry
|
|
|
|
|
//
|
|
|
|
|
SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders;
|
|
|
|
|
NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;
|
|
|
|
|
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
|
|
|
|
|
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);
|
|
|
|
|
} else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
|
|
|
|
|
//
|
|
|
|
|
// Use PE32+ offset get Debug Directory Entry
|
|
|
|
|
//
|
|
|
|
|
SizeOfHeaders = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders;
|
|
|
|
|
NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;
|
|
|
|
|
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
|
|
|
|
|
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
|
|
|
|
|
DirectoryEntry = NULL;
|
|
|
|
|
DebugEntry = NULL;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DebugEntry == NULL || DirectoryEntry == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {
|
|
|
|
|
if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {
|
|
|
|
|
if (DebugEntry->SizeOfData > 0) {
|
|
|
|
|
CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);
|
|
|
|
|
switch (* (UINT32 *) CodeViewEntryPointer) {
|
|
|
|
|
case CODEVIEW_SIGNATURE_NB10:
|
|
|
|
|
return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));
|
|
|
|
|
case CODEVIEW_SIGNATURE_RSDS:
|
|
|
|
|
return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));
|
|
|
|
|
case CODEVIEW_SIGNATURE_MTOC:
|
|
|
|
|
*DebugBase = (VOID *)(UINTN)((UINTN)DebugBase - SizeOfHeaders);
|
|
|
|
|
return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY));
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(void)SizeOfHeaders;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
/**
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Process "qXfer:object:read:annex:offset,length" request.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
Returns an XML document that contains loaded libraries. In our case it is
|
2013-03-12 01:45:29 +01:00
|
|
|
|
information in the EFI Debug Image Table converted into an XML document.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
GDB will call with an arbitrary length (it can't know the real length and
|
|
|
|
|
will reply with chunks of XML that are easy for us to deal with. Gdb will
|
2013-01-25 12:28:06 +01:00
|
|
|
|
keep calling until we say we are done. XML doc looks like:
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
<library-list>
|
|
|
|
|
<library name="/a/a/c/d.dSYM"><segment address="0x10000000"/></library>
|
|
|
|
|
<library name="/a/m/e/e.pdb"><segment address="0x20000000"/></library>
|
|
|
|
|
<library name="/a/l/f/f.dll"><segment address="0x30000000"/></library>
|
|
|
|
|
</library-list>
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
Since we can not allocate memory in interrupt context this module has
|
2013-01-25 12:28:06 +01:00
|
|
|
|
assumptions about how it will get called:
|
|
|
|
|
1) Length will generally be max remote packet size (big enough)
|
|
|
|
|
2) First Offset of an XML document read needs to be 0
|
|
|
|
|
3) This code will return back small chunks of the XML document on every read.
|
2013-03-12 01:45:29 +01:00
|
|
|
|
Each subsequent call will ask for the next available part of the document.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Note: The only variable size element in the XML is:
|
2014-08-19 15:29:52 +02:00
|
|
|
|
" <library name=\"%s\"><segment address=\"%p\"/></library>\n" and it is
|
2013-01-25 12:28:06 +01:00
|
|
|
|
based on the file path and name of the symbol file. If the symbol file name
|
|
|
|
|
is bigger than the max gdb remote packet size we could update this code
|
|
|
|
|
to respond back in chunks.
|
|
|
|
|
|
|
|
|
|
@param Offset offset into special data area
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@param Length number of bytes to read starting at Offset
|
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
QxferLibrary (
|
|
|
|
|
IN UINTN Offset,
|
|
|
|
|
IN UINTN Length
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
VOID *LoadAddress;
|
|
|
|
|
CHAR8 *Pdb;
|
|
|
|
|
UINTN Size;
|
|
|
|
|
|
|
|
|
|
if (Offset != gPacketqXferLibraryOffset) {
|
|
|
|
|
SendError (GDB_EINVALIDARG);
|
|
|
|
|
Print (L"\nqXferLibrary (%d, %d) != %d\n", Offset, Length, gPacketqXferLibraryOffset);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
// Force a retry from the beginning
|
2013-01-25 12:28:06 +01:00
|
|
|
|
gPacketqXferLibraryOffset = 0;
|
2013-03-12 01:45:29 +01:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Offset == 0) {
|
|
|
|
|
gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', "<library-list>\n");
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// The owner of the table may have had to ralloc it so grab a fresh copy every time
|
2014-08-19 15:29:52 +02:00
|
|
|
|
// we assume qXferLibrary will get called over and over again until the entire XML table is
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// returned in a tight loop. Since we are in the debugger the table should not get updated
|
|
|
|
|
gDebugTable = gDebugImageTableHeader->EfiDebugImageInfoTable;
|
|
|
|
|
gEfiDebugImageTableEntry = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
if (gDebugTable != NULL) {
|
|
|
|
|
for (; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) {
|
|
|
|
|
if (gDebugTable->NormalImage != NULL) {
|
2014-08-19 15:29:52 +02:00
|
|
|
|
if ((gDebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&
|
2013-01-25 12:28:06 +01:00
|
|
|
|
(gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {
|
|
|
|
|
Pdb = PeCoffLoaderGetDebuggerInfo (
|
2014-08-19 15:29:52 +02:00
|
|
|
|
gDebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase,
|
2013-01-25 12:28:06 +01:00
|
|
|
|
&LoadAddress
|
|
|
|
|
);
|
|
|
|
|
if (Pdb != NULL) {
|
|
|
|
|
Size = AsciiSPrint (
|
2014-08-19 15:29:52 +02:00
|
|
|
|
gXferLibraryBuffer,
|
|
|
|
|
sizeof (gXferLibraryBuffer),
|
|
|
|
|
" <library name=\"%a\"><segment address=\"0x%p\"/></library>\n",
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Pdb,
|
|
|
|
|
LoadAddress
|
|
|
|
|
);
|
|
|
|
|
if ((Size != 0) && (Size != (sizeof (gXferLibraryBuffer) - 1))) {
|
|
|
|
|
gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', gXferLibraryBuffer);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// Update loop variables so we are in the right place when we get back
|
|
|
|
|
gEfiDebugImageTableEntry++;
|
|
|
|
|
gDebugTable++;
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
2014-08-19 15:29:52 +02:00
|
|
|
|
// We could handle <library> entires larger than sizeof (gXferLibraryBuffer) here if
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// needed by breaking up into N packets
|
|
|
|
|
// "<library name=\"%s
|
|
|
|
|
// the rest of the string (as many packets as required
|
|
|
|
|
// \"><segment address=\"%d\"/></library> (fixed size)
|
|
|
|
|
//
|
|
|
|
|
// But right now we just skip any entry that is too big
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
}
|
2013-01-25 12:28:06 +01:00
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
}
|
2013-01-25 12:28:06 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
gXferObjectReadResponse ('l', "</library-list>\n");
|
|
|
|
|
gPacketqXferLibraryOffset = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Exception Hanldler for GDB. It will be called for all exceptions
|
|
|
|
|
registered via the gExceptionType[] array.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param ExceptionType Exception that is being processed
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
2013-01-25 12:28:06 +01:00
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
2014-08-19 15:29:52 +02:00
|
|
|
|
GdbExceptionHandler (
|
|
|
|
|
IN EFI_EXCEPTION_TYPE ExceptionType,
|
|
|
|
|
IN OUT EFI_SYSTEM_CONTEXT SystemContext
|
2013-01-25 12:28:06 +01:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINT8 GdbExceptionType;
|
|
|
|
|
CHAR8 *Ptr;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
if (ValidateException (ExceptionType, SystemContext) == FALSE) {
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RemoveSingleStep (SystemContext);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
GdbExceptionType = ConvertEFItoGDBtype (ExceptionType);
|
|
|
|
|
GdbSendTSignal (SystemContext, GdbExceptionType);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
for( ; ; ) {
|
|
|
|
|
ReceivePacket (gInBuffer, MAX_BUF_SIZE);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
switch (gInBuffer[0]) {
|
|
|
|
|
case '?':
|
|
|
|
|
GdbSendTSignal (SystemContext, GdbExceptionType);
|
|
|
|
|
break;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
case 'c':
|
2014-08-19 15:29:52 +02:00
|
|
|
|
ContinueAtAddress (SystemContext, gInBuffer);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case 'g':
|
|
|
|
|
ReadGeneralRegisters (SystemContext);
|
|
|
|
|
break;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
case 'G':
|
|
|
|
|
WriteGeneralRegisters (SystemContext, gInBuffer);
|
|
|
|
|
break;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
case 'H':
|
2014-08-19 15:29:52 +02:00
|
|
|
|
//Return "OK" packet since we don't have more than one thread.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
SendSuccess ();
|
|
|
|
|
break;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
case 'm':
|
|
|
|
|
ReadFromMemory (gInBuffer);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
|
WriteToMemory (gInBuffer);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'P':
|
|
|
|
|
WriteNthRegister (SystemContext, gInBuffer);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Still debugging this code. Not used in Darwin
|
|
|
|
|
//
|
2014-08-19 15:29:52 +02:00
|
|
|
|
case 'q':
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// General Query Packets
|
|
|
|
|
if (AsciiStrnCmp (gInBuffer, "qSupported", 10) == 0) {
|
|
|
|
|
// return what we currently support, we don't parse what gdb suports
|
|
|
|
|
AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "qXfer:libraries:read+;PacketSize=%d", MAX_BUF_SIZE);
|
|
|
|
|
SendPacket (gOutBuffer);
|
|
|
|
|
} else if (AsciiStrnCmp (gInBuffer, "qXfer:libraries:read::", 22) == 0) {
|
|
|
|
|
// ‘qXfer:libraries:read::offset,length
|
|
|
|
|
// gInBuffer[22] is offset string, ++Ptr is length string’
|
|
|
|
|
for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// Not sure if multi-radix support is required. Currently only support decimal
|
|
|
|
|
QxferLibrary (AsciiStrHexToUintn (&gInBuffer[22]), AsciiStrHexToUintn (++Ptr));
|
|
|
|
|
} if (AsciiStrnCmp (gInBuffer, "qOffsets", 10) == 0) {
|
|
|
|
|
AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "Text=1000;Data=f000;Bss=f000");
|
|
|
|
|
SendPacket (gOutBuffer);
|
|
|
|
|
} else {
|
|
|
|
|
//Send empty packet
|
|
|
|
|
SendNotSupported ();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 's':
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SingleStep (SystemContext, gInBuffer);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
return;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
case 'z':
|
|
|
|
|
RemoveBreakPoint (SystemContext, gInBuffer);
|
|
|
|
|
break;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
case 'Z':
|
|
|
|
|
InsertBreakPoint (SystemContext, gInBuffer);
|
|
|
|
|
break;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
default:
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//Send empty packet
|
|
|
|
|
SendNotSupported ();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Periodic callback for GDB. This function is used to catch a ctrl-c or other
|
2013-01-25 12:28:06 +01:00
|
|
|
|
break in type command from GDB.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
@param SystemContext Register content at time of the call
|
2013-01-25 12:28:06 +01:00
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
2014-08-19 15:29:52 +02:00
|
|
|
|
GdbPeriodicCallBack (
|
|
|
|
|
IN OUT EFI_SYSTEM_CONTEXT SystemContext
|
2013-01-25 12:28:06 +01:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
//
|
2014-08-19 15:29:52 +02:00
|
|
|
|
// gCtrlCBreakFlag may have been set from a previous F response package
|
|
|
|
|
// and we set the global as we need to process it at a point where we
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// can update the system context. If we are in the middle of processing
|
|
|
|
|
// a F Packet it is not safe to read the GDB serial stream so we need
|
|
|
|
|
// to skip it on this check
|
|
|
|
|
//
|
|
|
|
|
if (!gCtrlCBreakFlag && !gProcessingFPacket) {
|
|
|
|
|
//
|
2014-08-19 15:29:52 +02:00
|
|
|
|
// Ctrl-C was not pending so grab any pending characters and see if they
|
|
|
|
|
// are a Ctrl-c (0x03). If so set the Ctrl-C global.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//
|
|
|
|
|
while (TRUE) {
|
|
|
|
|
if (!GdbIsCharAvailable ()) {
|
|
|
|
|
//
|
|
|
|
|
// No characters are pending so exit the loop
|
|
|
|
|
//
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
if (GdbGetChar () == 0x03) {
|
|
|
|
|
gCtrlCBreakFlag = TRUE;
|
|
|
|
|
//
|
|
|
|
|
// We have a ctrl-c so exit the loop
|
|
|
|
|
//
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
if (gCtrlCBreakFlag) {
|
|
|
|
|
//
|
|
|
|
|
// Update the context to force a single step trap when we exit the GDB
|
2013-03-12 01:45:29 +01:00
|
|
|
|
// stub. This will transfer control to GdbExceptionHandler () and let
|
2013-01-25 12:28:06 +01:00
|
|
|
|
// us break into the program. We don't want to break into the GDB stub.
|
|
|
|
|
//
|
|
|
|
|
AddSingleStep (SystemContext);
|
|
|
|
|
gCtrlCBreakFlag = FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|