Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Esp32 gdbstub Component and fix Esp8266 syscall errno handling #2169

Merged
merged 3 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Sming/Arch/Esp32/Components/esp32/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@ FLASH_BOOT_CHUNKS := 0x1000=$(FLASH_BOOT_LOADER)

SDK_DEFAULT_PATH := $(COMPONENT_PATH)/sdk

##@Debugging

CACHE_VARS += GDB_CMDLINE
GDB_CMDLINE = trap '' INT; $(GDB) -x $(ARCH_TOOLS)/gdbinit $(TARGET_OUT)

##@Partitions

SDK_PARTITION_PATH := $(SDK_DEFAULT_PATH)/partitions
Expand Down
8 changes: 8 additions & 0 deletions Sming/Arch/Esp32/Components/gdbstub/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
GDB Stub for Esp32
==================

This defines the command line to use when ``make gdb`` is run.

Esp32 debugging is handled via JTAG interface.

No additional code is required as serial debugging is not (currently) implemented.
6 changes: 6 additions & 0 deletions Sming/Arch/Esp32/Components/gdbstub/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DEBUG_VARS += GDBSTUB_DIR
GDBSTUB_DIR := $(COMPONENT_PATH)

# Full GDB command line
CACHE_VARS += GDB_CMDLINE
GDB_CMDLINE = trap '' INT; $(GDB) -x $(ARCH_TOOLS)/gdbinit $(TARGET_OUT)
7 changes: 7 additions & 0 deletions Sming/Arch/Esp32/Components/gdbstub/gdb_syscall.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <gdb/gdb_syscall.h>

int gdb_syscall(const GdbSyscallInfo& info)
{
errno = ENODEV;
return -1;
}
29 changes: 29 additions & 0 deletions Sming/Arch/Esp32/Components/gdbstub/gdbstub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <gdb/gdb_hooks.h>

void gdb_enable(bool state)
{
}

GdbState gdb_present(void)
{
return eGDB_NotPresent;
}

void __attribute__((weak)) gdb_on_attach(bool attached)
{
}

void gdb_detach(void)
{
}



unsigned __gdb_no_op(void)
{
return 0;
}

//#define NOOP __attribute__((weak, alias("__gdb_no_op")))
//
//void gdb_on_attach(bool attached) NOOP;
1 change: 1 addition & 0 deletions Sming/Arch/Esp32/Components/sming-arch/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ COMPONENT_DEPENDS := \
fatfs \
esp_spiffs \
esp32 \
gdbstub \
esptool

#
Expand Down
1 change: 1 addition & 0 deletions Sming/Arch/Esp8266/Components/gdbstub/gdbhostio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void ATTR_GDBEXTERNFN gdbHandleHostIo(char* commandBuffer, unsigned cmdLen)
unsigned flags = GdbPacket::readHexValue(data);
++data; // Skip ,
unsigned mode = GdbPacket::readHexValue(data); // Skip mode (not used)
(void)mode;

FileOpenFlags openFlags;
if((flags & 0xff) == O_RDWR) {
Expand Down
26 changes: 12 additions & 14 deletions Sming/Arch/Esp8266/Components/gdbstub/gdbsyscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,26 @@ bool ATTR_GDBEXTERNFN gdb_syscall_complete(const char* data)
++data;
isNeg = true;
}
int len = GdbPacket::readHexValue(data);
int retcode = GdbPacket::readHexValue(data);
if(isNeg) {
len = -len;
retcode = -retcode;
}
syscall_info.result = retcode;

char ctrl_c_flag = '\0';

if(*data == ',') {
++data;
unsigned err = GdbPacket::readHexValue(data);
syscall_info.result = -err;
} else {
syscall_info.result = len;
errno = GdbPacket::readHexValue(data);

if(*data == ',') {
++data;
ctrl_c_flag = *data;
if(ctrl_c_flag) {
bitSet(gdb_state.flags, DBGFLAG_CTRL_BREAK);
}
}
} else {
switch(syscall_info.command) {
case eGDBSYS_gettimeofday: {
auto tv = syscall_info.gettimeofday.tv;
Expand Down Expand Up @@ -244,14 +250,6 @@ bool ATTR_GDBEXTERNFN gdb_syscall_complete(const char* data)
}
}

if(*data == ',') {
++data;
ctrl_c_flag = *data;
if(ctrl_c_flag) {
bitSet(gdb_state.flags, DBGFLAG_CTRL_BREAK);
}
}

if(syscall_info.callback != nullptr) {
System.queueCallback(TaskCallback(syscall_info.callback), &syscall_info);
}
Expand Down
6 changes: 3 additions & 3 deletions Sming/Arch/Esp8266/Components/libc/component.mk
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
COMPONENT_SRCDIRS :=
COMPONENT_INCDIRS := include
COMPONENT_SRCFILES := libc.c
COMPONENT_SRCDIRS := src

COMPONENT_DOXYGEN_INPUT := include/sys

ifeq ($(USE_NEWLIB),1)
COMPONENT_SRCFILES += libc_replacements.c
COMPONENT_SRCDIRS += src/newlib
EXTRA_LIBS += m c gcc
else
COMPONENT_SRCFILES += pgmspace.c
COMPONENT_SRCDIRS += src/oldlib
LIBDIRS += $(COMPONENT_PATH)/lib
EXTRA_LIBS += microc microgcc setjmp
endif
22 changes: 22 additions & 0 deletions Sming/Arch/Esp8266/Components/libc/src/oldlib/strerror.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/****
* Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
* Created 2015 by Skurydin Alexey
* http://github.com/SmingHub/Sming
* All files of the Sming Core are provided under the LGPL v3 license.
*
* strerror.c - microc library doesn't contain strerror_r
*
****/

#include <m_printf.h>

int __xpg_strerror_r(int err, char* buf, size_t bufSize)
{
m_snprintf(buf, bufSize, "ERROR #%u", err);
if(buf != NULL && bufSize > 0) {
buf[bufSize - 1] = '\0';
}
return 0;
}

int strerror_r(int err, char* buf, size_t bufSize) __attribute__((weak, alias("__xpg_strerror_r")));
1 change: 1 addition & 0 deletions Sming/Arch/Host/Components/gdbstub/gdb_syscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

int gdb_syscall(const GdbSyscallInfo& info)
{
errno = ENODEV;
return -1;
}