mdebug

cortex m series debugger
git clone http://frotz.net/git/mdebug.git
Log | Files | Refs | README | LICENSE

debugger.h (3503B)


      1 /* debugger.h
      2  *
      3  * Copyright 2011 Brian Swetland <swetland@frotz.net>
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 #ifndef _DEBUGGER_H_
     19 #define _DEBUGGER_H_
     20 
     21 typedef enum {
     22 	XDEFAULT,
     23 	XSWD,		// SWD transport & engine
     24 	XCORE,		// debugger core
     25 	XDATA,		// debugger command response
     26 	XGDB,		// messages from GDB bridge
     27 	XREMOTE,	// remote console messages
     28 } xpchan;
     29 
     30 #define printf __use_xprintf_in_debugger__
     31 extern void xprintf(xpchan ch, const char *fmt, ...);
     32 
     33 #define ERROR		-1
     34 #define ERROR_UNKNOWN 	-2
     35 
     36 #define LF_SWD		1
     37 #define LF_GDB		2
     38 
     39 extern unsigned log_flags;
     40 
     41 struct funcline {
     42 	struct funcline *next;
     43 	char text[0];
     44 };
     45 
     46 struct funcinfo {
     47 	struct funcinfo *next;
     48 	struct funcline *lines;
     49 	char name[0];
     50 };
     51 
     52 struct varinfo {
     53 	struct varinfo *next;
     54 	u32 value;
     55 	char name[0];
     56 };
     57 
     58 typedef struct {
     59 	const char *s;
     60 	unsigned n;
     61 } param;
     62 
     63 struct debugger_command {
     64 	const char *name;
     65 	const char *args;
     66 	int (*func)(int argc, param *argv);
     67 	const char *help;
     68 };
     69 
     70 /* provided by debugger-core.c */
     71 int debugger_command(char *line);
     72 int debugger_invoke(const char *cmd, unsigned argc, ...);
     73 int debugger_variable(const char *name, u32 *value);
     74 
     75 /* lock to protect underlying rswdp state */
     76 void debugger_init();
     77 void debugger_lock();
     78 void debugger_unlock();
     79 
     80 /* provided by debugger-commands.c */
     81 extern struct debugger_command debugger_commands[];
     82 int read_register(const char *name, u32 *value);
     83 int read_memory_word(u32 addr, u32 *value);
     84 
     85 typedef struct debug_transport {
     86 	// attempt to establish connection to target
     87 	int (*attach)(void);
     88 
     89 	// returns nonzero if target is in error state
     90 	// (one or more transactions have failed, attach needed)
     91 	int (*error)(void);
     92 
     93 	// if target is in error, clear error flag
     94 	// return nonzero if target was in error (attach needed)
     95 	int (*clear_error)(void);
     96 
     97 	// single 32bit memory access
     98 	int (*mem_rd_32)(u32 addr, u32 *value);
     99 	int (*mem_wr_32)(u32 addr, u32 value);
    100 
    101 	// multiple 32bit memory access
    102 	int (*mem_rd_32_c)(u32 addr, u32 *data, int count);
    103 	int (*mem_wr_32_c)(u32 addr, u32 *data, int count);
    104 } debug_transport;
    105 
    106 extern debug_transport *ACTIVE_TRANSPORT;
    107 
    108 static inline int debug_attach(void) {
    109 	return ACTIVE_TRANSPORT->attach();
    110 }
    111 static inline int debug_error(void) {
    112 	return ACTIVE_TRANSPORT->error();
    113 }
    114 static inline int debug_clear_error(void) {
    115 	return ACTIVE_TRANSPORT->clear_error();
    116 }
    117 static inline int mem_rd_32(u32 addr, u32 *value) {
    118 	return ACTIVE_TRANSPORT->mem_rd_32(addr, value);
    119 }
    120 static inline int mem_wr_32(u32 addr, u32 value) {
    121 	return ACTIVE_TRANSPORT->mem_wr_32(addr, value);
    122 }
    123 static inline int mem_rd_32_c(u32 addr, u32 *data, int count) {
    124 	return ACTIVE_TRANSPORT->mem_rd_32_c(addr, data, count);
    125 }
    126 static inline int mem_wr_32_c(u32 addr, u32 *data, int count) {
    127 	return ACTIVE_TRANSPORT->mem_wr_32_c(addr, data, count);
    128 }
    129 
    130 extern debug_transport DUMMY_TRANSPORT;
    131 extern debug_transport SWDP_TRANSPORT;
    132 extern debug_transport JTAG_TRANSPORT;
    133 
    134 int debug_target(const char* name);
    135 
    136 #endif
    137