1 /* 2 * Copyright 2005-2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2013, Rene Gollent, rene@gollent.com 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef _DEBUG_SUPPORT_H 7 #define _DEBUG_SUPPORT_H 8 9 #include <debugger.h> 10 #include <OS.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 typedef struct debug_context { 17 team_id team; 18 port_id nub_port; 19 port_id reply_port; 20 } debug_context; 21 22 23 status_t init_debug_context(debug_context *context, team_id team, 24 port_id nubPort); 25 void destroy_debug_context(debug_context *context); 26 27 status_t send_debug_message(debug_context *context, int32 messageCode, 28 const void *message, int32 messageSize, void *reply, 29 int32 replySize); 30 31 ssize_t debug_read_memory_partial(debug_context *context, const void *address, 32 void *buffer, size_t size); 33 ssize_t debug_read_memory(debug_context *context, const void *address, 34 void *buffer, size_t size); 35 ssize_t debug_read_string(debug_context *context, const void *_address, 36 char *buffer, size_t size); 37 ssize_t debug_write_memory_partial(debug_context *context, const void *address, 38 void *buffer, size_t size); 39 ssize_t debug_write_memory(debug_context *context, const void *address, 40 void *buffer, size_t size); 41 42 status_t debug_get_cpu_state(debug_context *context, thread_id thread, 43 debug_debugger_message *messageCode, debug_cpu_state *cpuState); 44 45 46 // stack trace support 47 48 typedef struct debug_stack_frame_info { 49 void *frame; 50 void *parent_frame; 51 void *return_address; 52 } debug_stack_frame_info; 53 54 status_t debug_get_instruction_pointer(debug_context *context, thread_id thread, 55 void **ip, void **stackFrameAddress); 56 status_t debug_get_stack_frame(debug_context *context, 57 void *stackFrameAddress, debug_stack_frame_info *stackFrameInfo); 58 59 60 // symbol lookup support 61 62 typedef struct debug_symbol_lookup_context debug_symbol_lookup_context; 63 typedef struct debug_symbol_iterator debug_symbol_iterator; 64 65 status_t debug_create_symbol_lookup_context(team_id team, image_id image, 66 debug_symbol_lookup_context **lookupContext); 67 // imageID can be -1 if all images in the target team are 68 // desired, otherwise a valid image id is expected. 69 70 void debug_delete_symbol_lookup_context( 71 debug_symbol_lookup_context *lookupContext); 72 73 status_t debug_get_symbol(debug_symbol_lookup_context* lookupContext, 74 image_id image, const char* name, int32 symbolType, 75 void** _symbolLocation, size_t* _symbolSize, int32* _symbolType); 76 status_t debug_lookup_symbol_address(debug_symbol_lookup_context *lookupContext, 77 const void *address, void **baseAddress, char *symbolName, 78 int32 symbolNameSize, char *imageName, int32 imageNameSize, 79 bool *exactMatch); 80 81 status_t debug_create_image_symbol_iterator( 82 debug_symbol_lookup_context* lookupContext, image_id imageID, 83 debug_symbol_iterator** _iterator); 84 85 status_t debug_create_file_symbol_iterator(const char* path, 86 debug_symbol_iterator** _iterator); 87 void debug_delete_symbol_iterator(debug_symbol_iterator* iterator); 88 89 status_t debug_next_image_symbol(debug_symbol_iterator* iterator, 90 char* nameBuffer, size_t nameBufferLength, int32* _symbolType, 91 void** _symbolLocation, size_t* _symbolSize); 92 status_t debug_get_symbol_iterator_image_info(debug_symbol_iterator* iterator, 93 image_info* info); 94 95 #ifdef __cplusplus 96 } // extern "C" 97 #endif 98 99 100 #endif // _DEBUG_SUPPORT_H 101