Skip to content

Commit f06eb4e

Browse files
SeppoTakalocarlescufi
authored andcommitted
Initial Zephyr J-Link GDBServer plugin
This implementation of the J-Link GDBServer RTOS-awareness plugin has been written mainly by Seppo Takalo with contributions from Jordan Yates and others. Includes the JLink GDBServer RTOS Plugin v1.20. Signed-off-by: Seppo Takalo <[email protected]> Signed-off-by: Jordan Yates <[email protected]> Signed-off-by: Carles Cufi <[email protected]> Signed-off-by: Torsten Rasmussen <[email protected]> Signed-off-by: Johannes Lask <[email protected]>
0 parents  commit f06eb4e

File tree

14 files changed

+5959
-0
lines changed

14 files changed

+5959
-0
lines changed

.github/workflows/build.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: 'Build and test'
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build-linux:
11+
name: Build and test (linux)
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
arch: [32, 64]
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Install 32bit cross compilation libs
21+
if: ${{matrix.arch == '32' }}
22+
run: sudo apt-get install -y libc6-dev-i386 gcc-multilib
23+
24+
- name: Generate CMake
25+
run: cmake -DCMAKE_C_FLAGS=-m${{ matrix.arch }} -B build
26+
27+
- name: Build
28+
run: cmake --build build
29+
30+
- name: Upload plugin artifact
31+
uses: actions/upload-artifact@v2
32+
with:
33+
name: linux-${{matrix.arch == '32' && 'x86' || 'x64'}}
34+
path: build/libzephyr_rtos.so
35+
36+
- name: Run unit tests
37+
run: ./build/unittests/plugin_test
38+
39+
40+
build-nix:
41+
name: Build and test (macOS)
42+
runs-on: macos-latest
43+
steps:
44+
- uses: actions/checkout@v3
45+
46+
- name: Generate CMake
47+
# Create universal build:
48+
run: cmake -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B build
49+
50+
- name: Build
51+
run: cmake --build build
52+
53+
- name: Upload plugin artifact
54+
uses: actions/upload-artifact@v2
55+
with:
56+
name: macos-universal
57+
path: build/libzephyr_rtos.so
58+
59+
- name: Run unit tests
60+
run: ./build/unittests/plugin_test
61+
62+
63+
build-win:
64+
name: Build and test (Windows)
65+
strategy:
66+
fail-fast: false
67+
matrix:
68+
arch: [win32, x64]
69+
runs-on: windows-latest
70+
steps:
71+
- uses: actions/checkout@v3
72+
73+
- name: Generate CMake
74+
run: cmake -A ${{ matrix.arch }} -B build
75+
76+
- name: Build
77+
run: cmake --build build --config Release
78+
79+
- name: Upload plugin artifact
80+
uses: actions/upload-artifact@v2
81+
with:
82+
name: ${{runner.os}}-${{matrix.arch == 'win32' && 'x86' || 'x64'}}
83+
path: build/Release/zephyr_rtos.dll
84+
85+
- name: Run unit tests
86+
run: ./build/unittests/Release/plugin_test.exe

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/*

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(ZephyrRTOSPlugin)
4+
5+
add_library (zephyr_rtos MODULE zephyr_plugin.c)
6+
7+
if (NOT MSVC)
8+
# lots of warnings and all warnings as errors
9+
target_compile_options(zephyr_rtos PRIVATE -Wall -Wextra -pedantic -Werror)
10+
endif()
11+
12+
target_include_directories (zephyr_rtos PUBLIC
13+
${CMAKE_CURRENT_SOURCE_DIR}/JLinkGDBServer_RTOSPlugin_SDK_V120)
14+
15+
add_subdirectory(unittests)

JLinkGDBServer_RTOSPlugin_SDK_V120/JLINKARM_Const.h

Lines changed: 2383 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Important - Read carefully:
2+
3+
This is a legal agreement between YOU as an individual and SEGGER Microcontroller GmbH (hereafter called SEGGER).
4+
All IP rights, title and interest in the GDBServer RTOS Plug-in SDK (hereafter called Plug-in SDK) is and shall at all times remain with SEGGER.
5+
The Plug-in SDK allows you to write an own RTOS plug-in for the J-Link GDB server.
6+
Prior use of the Plug-in SDK YOU agree to be bound by the terms of this agreement.
7+
The Plug-in SDK is licensed and not sold to YOU for use only under the terms of this agreement.
8+
YOU acknowledge and agree that the Plug-in SDK consists of proprietary and copyright protected components. Title, ownership rights, and intellectual property rights in the
9+
Plug-in SDK shall remain by SEGGER. YOU acknowledge such ownership and intellectual property rights and YOU will not take any action to jeopardize, limit or interfere in any manner with SEGGER ownership rights.
10+
11+
12+
1. License Grant
13+
The Plug-in SDK is provided in source code form.
14+
YOU may use the Plug-in SDK for personal or for commercial purposes.
15+
The Plug-in developed by YOU can be shipped or distributed by YOU in source code and/or binary form free of charge only.
16+
17+
18+
2. RESTRICTIONS
19+
YOU may not:
20+
(a) decompile, disassemble, reverse engineer, or otherwise attempt to derive the source code of Plug-in SDK components (if any) provided in binary or executable code form,
21+
(b) redistribute, encumber, sell, rent, lease, sublicense, or otherwise transfer rights to the Plug-in SDK,
22+
(c) remove or alter any trademark, logo, copyright or other proprietary notices, legends, symbols or label in the Plug-in SDK,
23+
(d) use the GDBServer RTOS Plug-in for any competitive product
24+
25+
Without prejudice to any other rights, SEGGER may terminate this agreement if YOU fail to comply with foregoing restrictions.
26+
27+
3. FEES
28+
The Plug-in SDK can be used free of charge without purchasing a license. The Plug-in SDK is licensed and not sold to YOU for use only under the terms of this agreement. YOU acknowledge and agree that the product consists of proprietary, unpublished products of SEGGER, protected under copyright and trade secret laws. Title, ownership rights, and intellectual property rights in the product shall remain by SEGGER and/or its suppliers. Licensee acknowledges such ownership and intellectual property rights and will not take any action to jeopardize, limit or interfere in any manner with SEGGER or its suppliers' ownership of or rights with respect to the product.
29+
30+
4. DISCLAIMER OF WARRANTY
31+
The Plug-in SDK is provided on an "as is" basis, without warranty of any kind or support from SEGGER, including without limitation the warranties that it is free of defects, merchantable, fit for a particular purpose or non-infringing. This disclaimer of warranty constitutes an essential part of this agreement. No use of the Plug-in SDK is authorized hereunder except under this disclaimer.
32+
33+
5. LIMITATION OF LIABILITY
34+
To the maximum extent permitted by applicable law, in no event will SEGGER be liable for any indirect, special, incidental or consequential damages arising out of the use of or inability to use The Plug-in SDK, including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other damages or losses, even if advised of the possibility thereof, and regardless of the legal or equitable theory (contract, tort or otherwise) upon which the claim is based. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not be applicable. In any case, SEGGER's entire liability shall not exceed in aggregate the sum of the fees YOU paid for the Plug-in SDK (if any).
35+
36+
6. MISCELLANEOUS
37+
(a) This agreement shall be governed by the laws of the Federal Republic of Germany. This agreement constitutes the entire agreement between the parties concerning the subject matter hereof.
38+
(b) If any provision in this agreement should be held illegal or unenforceable by a court having jurisdiction, such provision shall be modified to the extent necessary to render it enforceable without losing its intent, or severed from this agreement if no such modification is possible, and other provisions of this agreement shall remain in full force and effect.This agreement may be changed only by an amendment in writing, signed by both parties.
39+
(c) If any SEGGER professional services are being provided, then such professional services are provided pursuant to the terms of a separate agreement.
40+
41+
42+
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*********************************************************************
2+
* SEGGER MICROCONTROLLER SYSTEME GmbH *
3+
* Solutions for real time microcontroller applications *
4+
**********************************************************************
5+
* *
6+
* (C) 2004-2009 SEGGER Microcontroller Systeme GmbH *
7+
* *
8+
* Internet: www.segger.com Support: [email protected] *
9+
* *
10+
**********************************************************************
11+
----------------------------------------------------------------------
12+
File : RTOSPlugin.h
13+
Purpose : RTOS plugin header
14+
---------------------------END-OF-HEADER------------------------------
15+
*/
16+
17+
#ifndef RTOSPLUGIN_H // Guard against multiple inclusion
18+
#define RTOSPLUGIN_H
19+
20+
#include "JLINKARM_Const.h"
21+
#include "TYPES.h"
22+
23+
#if defined(__cplusplus) // Allow usage of this module from C++ files (disable name mangling)
24+
extern "C" {
25+
#endif
26+
27+
/*********************************************************************
28+
*
29+
* Defines
30+
*
31+
**********************************************************************
32+
*/
33+
34+
#define RTOS_PLUGIN_BUF_SIZE_THREAD_DISPLAY 256 // Size of buffer in bytes that is passed to RTOS_GetThreadDisplay()
35+
36+
/*********************************************************************
37+
*
38+
* Types
39+
*
40+
**********************************************************************
41+
*/
42+
43+
enum RTOS_PLUGIN_CPU_REGS_CORTEX_M {
44+
//
45+
// These register indexes must NOT be in line with the J-Link DLL register indexes,
46+
// nor the GDB register indexes (because the GDB indexes may change, depending on if J-Link GDBServer reports a different Target.xml file to GDB
47+
// These indexes have been determined once and stay fixed to guarantee binary compatibility between different GDBServer versions
48+
//
49+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R0=0, // 32-bit reg
50+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R1, // 32-bit reg
51+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R2, // 32-bit reg
52+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R3, // 32-bit reg
53+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R4, // 32-bit reg
54+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R5, // 32-bit reg
55+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R6, // 32-bit reg
56+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R7, // 32-bit reg
57+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R8, // 32-bit reg
58+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R9, // 32-bit reg
59+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R10, // 32-bit reg
60+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R11, // 32-bit reg
61+
RTOS_PLUGIN_CPU_REG_CORTEX_M_R12, // 32-bit reg
62+
RTOS_PLUGIN_CPU_REG_CORTEX_M_SP, // 32-bit reg
63+
RTOS_PLUGIN_CPU_REG_CORTEX_M_LR, // 32-bit reg
64+
RTOS_PLUGIN_CPU_REG_CORTEX_M_PC, // 32-bit reg
65+
RTOS_PLUGIN_CPU_REG_CORTEX_M_XPSR, // 32-bit reg
66+
RTOS_PLUGIN_CPU_REG_CORTEX_M_MSP, // 32-bit reg
67+
RTOS_PLUGIN_CPU_REG_CORTEX_M_PSP, // 32-bit reg
68+
RTOS_PLUGIN_CPU_REG_CORTEX_M_PRIMASK, // 32-bit reg
69+
RTOS_PLUGIN_CPU_REG_CORTEX_M_BASEPRI, // 32-bit reg
70+
RTOS_PLUGIN_CPU_REG_CORTEX_M_FAULTMASK, // 32-bit reg
71+
RTOS_PLUGIN_CPU_REG_CORTEX_M_CONTROL, // 32-bit reg
72+
RTOS_PLUGIN_CPU_REG_CORTEX_M_FPSCR, // 32-bit reg
73+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S0, // 32-bit reg
74+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S1, // 32-bit reg
75+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S2, // 32-bit reg
76+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S3, // 32-bit reg
77+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S4, // 32-bit reg
78+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S5, // 32-bit reg
79+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S6, // 32-bit reg
80+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S7, // 32-bit reg
81+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S8, // 32-bit reg
82+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S9, // 32-bit reg
83+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S10, // 32-bit reg
84+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S11, // 32-bit reg
85+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S12, // 32-bit reg
86+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S13, // 32-bit reg
87+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S14, // 32-bit reg
88+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S15, // 32-bit reg
89+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S16, // 32-bit reg
90+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S17, // 32-bit reg
91+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S18, // 32-bit reg
92+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S19, // 32-bit reg
93+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S20, // 32-bit reg
94+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S21, // 32-bit reg
95+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S22, // 32-bit reg
96+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S23, // 32-bit reg
97+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S24, // 32-bit reg
98+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S25, // 32-bit reg
99+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S26, // 32-bit reg
100+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S27, // 32-bit reg
101+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S28, // 32-bit reg
102+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S29, // 32-bit reg
103+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S30, // 32-bit reg
104+
RTOS_PLUGIN_CPU_REG_CORTEX_M_S31, // 32-bit reg
105+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D0, // 64-bit reg
106+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D1, // 64-bit reg
107+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D2, // 64-bit reg
108+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D3, // 64-bit reg
109+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D4, // 64-bit reg
110+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D5, // 64-bit reg
111+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D6, // 64-bit reg
112+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D7, // 64-bit reg
113+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D8, // 64-bit reg
114+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D9, // 64-bit reg
115+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D10, // 64-bit reg
116+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D11, // 64-bit reg
117+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D12, // 64-bit reg
118+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D13, // 64-bit reg
119+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D14, // 64-bit reg
120+
RTOS_PLUGIN_CPU_REG_CORTEX_M_D15, // 64-bit reg
121+
RTOS_PLUGIN_CPU_REG_CORTEX_M_NUMREGS
122+
};
123+
124+
//
125+
// RTOS symbols
126+
//
127+
typedef struct {
128+
const char *name;
129+
int optional;
130+
U32 address;
131+
} RTOS_SYMBOLS;
132+
133+
//
134+
// GDB server functions that can be called by the plugin
135+
//
136+
typedef struct {
137+
//
138+
// API version v1.0 and higher
139+
//
140+
void (*pfFree) (void* p);
141+
void* (*pfAlloc) (unsigned Size);
142+
void* (*pfRealloc) (void* p, unsigned Size);
143+
void (*pfLogOutf) (const char* sFormat, ...);
144+
void (*pfDebugOutf) (const char* sFormat, ...);
145+
void (*pfWarnOutf) (const char* sFormat, ...);
146+
void (*pfErrorOutf) (const char* sFormat, ...);
147+
int (*pfReadMem) (U32 Addr, char* pData, unsigned int NumBytes);
148+
char (*pfReadU8) (U32 Addr, U8* pData);
149+
char (*pfReadU16) (U32 Addr, U16* pData);
150+
char (*pfReadU32) (U32 Addr, U32* pData);
151+
int (*pfWriteMem) (U32 Addr, const char* pData, unsigned NumBytes);
152+
void (*pfWriteU8) (U32 Addr, U8 Data);
153+
void (*pfWriteU16) (U32 Addr, U16 Data);
154+
void (*pfWriteU32) (U32 Addr, U32 Data);
155+
U32 (*pfLoad16TE) (const U8* p);
156+
U32 (*pfLoad24TE) (const U8* p);
157+
U32 (*pfLoad32TE) (const U8* p);
158+
//
159+
// API version v1.1 and higher
160+
//
161+
U32 (*pfReadReg) (U32 RegIndex);
162+
void (*pfWriteReg) (U32 RegIndex, U32 Value);
163+
//
164+
// End marker
165+
//
166+
void *Dummy;
167+
} GDB_API;
168+
169+
#if defined(__cplusplus) // Allow usage of this module from C++ files (disable name mangling)
170+
}
171+
#endif
172+
173+
#endif // Avoid multiple inclusion
174+
175+
/*************************** End of file ****************************/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*********************************************************************
2+
* SEGGER MICROCONTROLLER SYSTEME GmbH *
3+
* Solutions for real time microcontroller applications *
4+
**********************************************************************
5+
* *
6+
* (C) 2003 SEGGER Microcontroller Systeme GmbH *
7+
* *
8+
* Internet: www.segger.com Support: [email protected] *
9+
* *
10+
**********************************************************************
11+
----------------------------------------------------------------------
12+
File : Types.h
13+
Purpose : Global data types
14+
---------------------------END-OF-HEADER------------------------------
15+
*/
16+
17+
#ifndef TYPES_H // Guard against multiple inclusion
18+
#define TYPES_H
19+
20+
/*********************************************************************
21+
*
22+
* Defines, basic types
23+
*
24+
**********************************************************************
25+
*/
26+
27+
#define U8 unsigned char
28+
#define U16 unsigned short
29+
#define U32 unsigned int
30+
#define I8 signed char
31+
#define I16 signed short
32+
#define I32 signed int
33+
34+
#ifdef _MSC_VER
35+
#define U64 unsigned __int64
36+
#define I64 signed __int64
37+
#if _MSC_VER <= 1200
38+
#define U64_C(x) x##UI64
39+
#else
40+
#define U64_C(x) x##ULL
41+
#endif
42+
#else
43+
#define U64 unsigned long long
44+
#define I64 signed long long
45+
#define U64_C(x) x##ULL
46+
#endif
47+
48+
#endif // Avoid multiple inclusion
49+
50+
/*************************** End of file ****************************/

0 commit comments

Comments
 (0)