Skip to content

Commit

Permalink
Further tweaks to vs code launch (need to backport to template). And,…
Browse files Browse the repository at this point in the history
… also, improvements to windows GDB.
  • Loading branch information
cnlohr committed Nov 15, 2024
1 parent 501387a commit c50b6bf
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
10 changes: 2 additions & 8 deletions examples/debugprintfdemo/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"deploySteps": [
{
"type": "shell",
"continueOn": "GDBServer",
"command": "make --directory=${workspaceFolder} closechlink flash gdbserver"
},
],
"preLaunchTask": "run_flash_and_gdbserver",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
Expand All @@ -33,7 +27,7 @@
"type": "node",
"request": "launch",
"program": "",
"preLaunchTask": "run_flash_and_gdbserver",
"preLaunchTask": "run_flash_and_monitor",
}
]
}
14 changes: 13 additions & 1 deletion examples/debugprintfdemo/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,22 @@
},
"command": "make closechlink flash",
},
{
"type": "shell",
"label": "run_flash_and_monitor",
"presentation": {
"echo": true,
"focus": false,
"group": "build",
"panel": "shared",
"showReuseMessage" : false
},
"command": "make flash monitor",
},
{
"type": "shell",
"label": "run_flash_and_gdbserver",
"command": "make closechlink flash gdbserver",
"command": "make flash gdbserver",

"presentation": {
"echo": true,
Expand Down
20 changes: 15 additions & 5 deletions minichlink/microgdbstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void RVNetConnect( void * dev );
int RVGetNumRegisters( void * dev );
int RVReadCPURegister( void * dev, int regno, uint32_t * regret );
int RVWriteCPURegister( void * dev, int regno, uint32_t value );
int RVDebugExec( void * dev, enum HaltResetResumeType halt_reset_or_resume );
int RVDebugExec( void * dev, enum HaltResetResumeType halt_reset_or_resume, int resume_from_other_address, uint32_t address );
int RVReadMem( void * dev, uint32_t memaddy, uint8_t * payload, int len );
int RVHandleBreakpoint( void * dev, int set, uint32_t address );
int RVWriteRAM(void * dev, uint32_t memaddy, uint32_t length, uint8_t * payload );
Expand Down Expand Up @@ -217,7 +217,7 @@ void HandleGDBPacket( void * dev, char * data, int len )
if( StringMatch( data, "Attached" ) )
SendReplyFull( "1" ); //Attached to an existing process.
else if( StringMatch( data, "Supported" ) )
SendReplyFull( "PacketSize=f000;qXfer:memory-map:read+" );
SendReplyFull( "PacketSize=f000;multiprocess+;hwbreak+;vContSupported+;qXfer:memory-map:read+" );
else if( StringMatch( data, "C") ) // Get Current Thread ID. (Can't be -1 or 0. Those are special)
SendReplyFull( "QC1" );
else if( StringMatch( data, "fThreadInfo" ) ) // Query all active thread IDs (Can't be 0 or 1)
Expand Down Expand Up @@ -306,13 +306,17 @@ void HandleGDBPacket( void * dev, char * data, int len )
break;
case 'c':
case 'C':
RVDebugExec( dev, (cmd == 'C')?HALT_TYPE_CONTINUE_WITH_SIGNAL:HALT_TYPE_CONTINUE );
// TODO: Support continue-from-another-address
RVDebugExec( dev, (cmd == 'C')?HALT_TYPE_CONTINUE_WITH_SIGNAL:HALT_TYPE_CONTINUE, 0, 0 );
//SendReplyFull( "OK" ); ... this will be sent from RVNetPoll
break;
case 's':
RVDebugExec( dev, HALT_TYPE_SINGLE_STEP );
case 'S':
// TODO: Support step-with-signal.
RVDebugExec( dev, HALT_TYPE_SINGLE_STEP, 0, 0 );
//SendReplyFull( "T05" );
//SendReplyFull( "OK" ); // Will be sent from RVNetPoll
//RVHandleGDBBreakRequest( dev );
RVHandleGDBBreakRequest( dev );
RVSendGDBHaltReason( dev );
break;
case 'D':
Expand Down Expand Up @@ -421,6 +425,12 @@ void HandleGDBPacket( void * dev, char * data, int len )
{
SendReplyFull( "OK" );
}
else if( StringMatch( data, "Kill" ) ) //vKill
{
SendReplyFull( "OK" );
fprintf( stderr, "Received Kill command. Exiting\n" );
exit( 0 );
}
else if( StringMatch( data, "FlashErase" ) ) //vFlashErase
{
data += 10; // FlashErase
Expand Down
26 changes: 18 additions & 8 deletions minichlink/minichgdb.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// This file is loosely based on aappleby's GDBServer.

// Connect in with:
// gdb-multiarch -ex 'target remote :2000' ./blink.elf
// Optionally, use these commands:
// set debug remote 1
// target extended-remote :2000
// gdb-multiarch -ex "set debug remote 1" -ex "target extended-remote :2000" ./blink.elf
// gdb-multiarch -ex "target extended-remote :2000" ./blink.elf

#include "minichlink.h"

Expand All @@ -15,7 +13,7 @@
const char* MICROGDBSTUB_MEMORY_MAP = "l<?xml version=\"1.0\"?>"
"<!DOCTYPE memory-map PUBLIC \"+//IDN gnu.org//DTD GDB Memory Map V1.0//EN\" \"http://sourceware.org/gdb/gdb-memory-map.dtd\">"
"<memory-map>"
" <memory type=\"flash\" start=\"0x00000000\" length=\"0x%x\">"
" <memory type=\"ram\" start=\"0x00000000\" length=\"0x%x\">"
" <property name=\"blocksize\">%d</property>"
" </memory>"
" <memory type=\"ram\" start=\"0x20000000\" length=\"0x%x\">"
Expand Down Expand Up @@ -113,7 +111,7 @@ void RVNetPoll(void * dev )
return;
}
int statusrunning = ((status & (1<<10)));

static int laststatus;
if( status != laststatus )
{
Expand Down Expand Up @@ -210,7 +208,7 @@ int RVWriteCPURegister( void * dev, int regno, uint32_t value )
return 0;
}

int RVDebugExec( void * dev, enum HaltResetResumeType halt_reset_or_resume )
int RVDebugExec( void * dev, enum HaltResetResumeType halt_reset_or_resume, int resume_from_other_address, uint32_t address )
{
struct InternalState * iss = (struct InternalState*)(((struct ProgrammerStructBase*)dev)->internal);
int nrregs = iss->nr_registers_for_debug;
Expand All @@ -220,6 +218,18 @@ int RVDebugExec( void * dev, enum HaltResetResumeType halt_reset_or_resume )
fprintf( stderr, "Error: Can't alter halt mode with this programmer.\n" );
exit( -6 );
}

if( halt_reset_or_resume == HALT_TYPE_SINGLE_STEP )
{
MCF.SetEnableBreakpoints( dev, 1, 1 );
RVCommandEpilogue( dev );
MCF.HaltMode( dev, HALT_MODE_RESUME );
MCF.HaltMode( dev, HALT_MODE_HALT_BUT_NO_RESET );
RVCommandPrologue( dev );
MCF.SetEnableBreakpoints( dev, 1, 0 );
return 0;
}

// Special case halt_reset_or_resume = 4: Skip instruction and resume.
if( halt_reset_or_resume == HALT_TYPE_CONTINUE_WITH_SIGNAL || halt_reset_or_resume == HALT_TYPE_CONTINUE )
{
Expand Down Expand Up @@ -296,7 +306,7 @@ int RVDebugExec( void * dev, enum HaltResetResumeType halt_reset_or_resume )
RVCommandEpilogue( dev );
}

MCF.HaltMode( dev, (halt_reset_or_resume == HALT_TYPE_SINGLE_STEP)?HALT_TYPE_CONTINUE:halt_reset_or_resume );
MCF.HaltMode( dev, halt_reset_or_resume );
}

shadow_running_state = halt_reset_or_resume >= HALT_TYPE_CONTINUE;
Expand Down
Binary file modified minichlink/minichlink.exe
Binary file not shown.

0 comments on commit c50b6bf

Please sign in to comment.