Skip to content

Commit b956495

Browse files
anjiahao1xiaoxiang781216
authored andcommitted
libs/libc:Support gdb rsp protocol
you can debug nuttx through any transport layer (serial port, network etc.), currently supports the following functions: 1. Read and write registers 2. Read and write memory 3. Switch thread and read stack information Future support plans: 1. Support breakpoint, watch point (requires architecture support). related information: https://sourceware.org/gdb/onlinedocs/gdb/Remote-Protocol.html Signed-off-by: anjiahao <[email protected]>
1 parent 97309dd commit b956495

File tree

6 files changed

+1726
-0
lines changed

6 files changed

+1726
-0
lines changed

include/nuttx/gdbstub.h

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/****************************************************************************
2+
* include/nuttx/gdbstub.h
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
#ifndef __INCLUDE_NUTTX_GDBSTUB_H
22+
#define __INCLUDE_NUTTX_GDBSTUB_H
23+
24+
/****************************************************************************
25+
* Included Files
26+
****************************************************************************/
27+
28+
#include <stdlib.h>
29+
30+
/****************************************************************************
31+
* Type Definitions
32+
****************************************************************************/
33+
34+
struct gdb_state_s;
35+
typedef CODE ssize_t (*gdb_send_func_t)(FAR void *priv, FAR void *buf,
36+
size_t len);
37+
typedef CODE ssize_t (*gdb_recv_func_t)(FAR void *priv, FAR void *buf,
38+
size_t len);
39+
40+
typedef CODE int (*gdb_monitor_func_t)(FAR struct gdb_state_s *state,
41+
FAR const char *cmd);
42+
43+
/****************************************************************************
44+
* Name: gdb_state_init
45+
*
46+
* Description:
47+
* Initialize the GDB state structure.
48+
*
49+
* Input Parameters:
50+
* send - The pointer to the send function.
51+
* recv - The pointer to the receive function.
52+
* monitor - The pointer to the monitor function.
53+
* priv - The pointer to the private data.
54+
*
55+
* Returned Value:
56+
* The pointer to the GDB state structure on success.
57+
* NULL on failure.
58+
*
59+
****************************************************************************/
60+
61+
FAR struct gdb_state_s *gdb_state_init(gdb_send_func_t send,
62+
gdb_recv_func_t recv,
63+
gdb_monitor_func_t monitor,
64+
FAR void *priv);
65+
66+
/****************************************************************************
67+
* Name: gdb_state_uninit
68+
*
69+
* Description:
70+
* Uninitialize the GDB state structure.
71+
*
72+
* Input Parameters:
73+
* state - The pointer to the GDB state structure.
74+
*
75+
****************************************************************************/
76+
77+
void gdb_state_uninit(FAR struct gdb_state_s *state);
78+
79+
/****************************************************************************
80+
* Name: gdb_console_message
81+
*
82+
* Description:
83+
* Send a message to the GDB console (via O XX... packet).
84+
*
85+
* Input Parameters:
86+
* state - The pointer to the GDB state structure.
87+
*
88+
* Returned Value:
89+
* Zero on success.
90+
* Negative value on error.
91+
*
92+
****************************************************************************/
93+
94+
int gdb_console_message(FAR struct gdb_state_s *state, FAR const char *msg);
95+
96+
/****************************************************************************
97+
* Name: gdb_process
98+
*
99+
* Description:
100+
* Main debug loop. Handles commands.
101+
*
102+
* Input Parameters:
103+
* state - The pointer to the GDB state structure.
104+
*
105+
* Returned Value:
106+
* Zero if successful.
107+
* Negative value on error.
108+
*
109+
****************************************************************************/
110+
111+
int gdb_process(FAR struct gdb_state_s *state);
112+
113+
#endif /* __INCLUDE_NUTTX_GDBSTUB_H */

libs/libc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ source "libs/libc/string/Kconfig"
1414
source "libs/libc/pthread/Kconfig"
1515
source "libs/libc/dlfcn/Kconfig"
1616
source "libs/libc/modlib/Kconfig"
17+
source "libs/libc/gdbstub/Kconfig"
1718
source "libs/libc/grp/Kconfig"
1819
source "libs/libc/pwd/Kconfig"
1920
source "libs/libc/locale/Kconfig"

libs/libc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ include dlfcn/Make.defs
3030
include errno/Make.defs
3131
include eventfd/Make.defs
3232
include fixedmath/Make.defs
33+
include gdbstub/Make.defs
3334
include grp/Make.defs
3435
include hex2bin/Make.defs
3536
include inttypes/Make.defs

libs/libc/gdbstub/Kconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config LIB_GDBSTUB
7+
tristate "GDBSTUB"
8+
depends on DEBUG_TCBINFO
9+
---help---
10+
Enable support for gdbstub.
11+
12+
if LIB_GDBSTUB
13+
14+
config LIB_GDBSTUB_DEBUG
15+
bool "Gdbstub Debug Info"
16+
default n
17+
---help---
18+
Add debug info to gdbstub
19+
20+
endif

libs/libc/gdbstub/Make.defs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
############################################################################
2+
# libs/libc/gdbstub/Make.defs
3+
#
4+
# Licensed to the Apache Software Foundation (ASF) under one or more
5+
# contributor license agreements. See the NOTICE file distributed with
6+
# this work for additional information regarding copyright ownership. The
7+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance with the
9+
# License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
# License for the specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
############################################################################
20+
21+
ifeq ($(CONFIG_LIB_GDBSTUB),y)
22+
23+
# Add the internal C files to the build
24+
25+
CSRCS += lib_gdbstub.c
26+
27+
# Add the userfs directory to the build
28+
29+
DEPPATH += --dep-path gdbstub
30+
VPATH += :gdbstub
31+
32+
endif

0 commit comments

Comments
 (0)