memory debugging

This commit is contained in:
Allen Webster 2016-06-07 16:12:23 -04:00
parent 412ad98864
commit 368e79e78c
5 changed files with 187 additions and 99 deletions

View File

@ -73,3 +73,4 @@ end_temp_memory(Temp_Memory temp){
}
#endif

View File

@ -181,6 +181,8 @@ FSTRING_INLINE fstr_bool terminate_with_null(String *str){
return result;
}
FSTRING_LINK fstr_bool append_padding(String *dest, char c, int32_t target_size);
FSTRING_LINK int32_t compare(char *a, char *b);
FSTRING_LINK int32_t compare(String a, char *b);
FSTRING_INLINE int32_t compare(char *a, String b) { return -compare(b,a); }
@ -1023,6 +1025,22 @@ append(String *dest, char c){
return result;
}
FSTRING_LINK fstr_bool
append_padding(String *dest, char c, int32_t target_size){
fstr_bool result = 1;
int32_t offset = target_size - dest->size;
int32_t r;
if (offset > 0){
for (r = 0; r < offset; ++r){
if (append(dest, c) == 0){
result = 0;
break;
}
}
}
return(result);
}
FSTRING_LINK int32_t
compare(char *a, char *b){
int32_t i = 0;

View File

@ -1247,7 +1247,10 @@ COMMAND_DECL(open_menu){
COMMAND_DECL(open_debug){
USE_VIEW(view);
#if FRED_INTERNAL
view_show_GUI(view, VUI_Debug);
view->debug_mode = DBG_Input;
#endif
}
COMMAND_DECL(user_callback){
@ -1523,6 +1526,7 @@ COMMAND_DECL(command_line){
if (bind_to_new_view){
view_set_file(view, file, models);
view_show_file(view);
}
proc = procs + vars->cli_processes.count++;

View File

@ -130,6 +130,11 @@ enum View_UI{
VUI_Debug
};
enum Debug_Mode{
DBG_Input,
DBG_Memory
};
enum Color_View_Mode{
CV_Mode_Library,
CV_Mode_Font,
@ -259,6 +264,8 @@ struct View{
f32 widget_height;
b32 reinit_scrolling;
Debug_Mode debug_mode;
};
inline void*
get_view_body(View *view){
@ -3906,7 +3913,9 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
gui_begin_top_level(target, input);
{
if (view->showing_ui != VUI_Debug){
gui_do_top_bar(target);
}
do_widget(view, target);
if (view->showing_ui == VUI_None){
@ -4473,15 +4482,19 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
#if FRED_INTERNAL
case VUI_Debug:
{
GUI_id scroll_context = {0};
scroll_context.id[1] = VUI_Debug + ((u64)view->interaction << 32);
view->current_scroll = &view->gui_scroll;
// TODO(allen):
// - Incoming input
// - Memory info
// + Incoming input
// + Memory info
// - Thread info
// - View inspection
// - Buffer inspection
// - Command maps inspection
// - Clipboard
String empty_str = string_zero();
@ -4499,8 +4512,32 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
gui_do_text_field(target, string, empty_str);
}
// Incoming input
// - convert mouse clicks into key coded events??!!
{
Debug_Mode prev_mode = view->debug_mode;
for (i32 i = 0; i < keys.count; ++i){
Key_Event_Data key = get_single_key(&keys, i);
if (key.modifiers[MDFR_CONTROL_INDEX] == 0 &&
key.modifiers[MDFR_ALT_INDEX] == 0){
if (key.keycode == 'i'){
view->debug_mode = DBG_Input;
}
if (key.keycode == 'm'){
view->debug_mode = DBG_Memory;
}
}
}
if (prev_mode != view->debug_mode){
result.consume_keys = 1;
}
}
gui_begin_scrollable(target, scroll_context, view->gui_scroll,
9.f * view->line_height, show_scrollbar);
switch (view->debug_mode)
{
case DBG_Input:
{
Debug_Data *debug = &view->persistent.models->debug;
@ -4577,19 +4614,47 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
}
if (input_event->consumer[0] != 0){
i32 next_pos = 40;
i32 offset = next_pos - string.size;
if (offset < 0) offset = 0;
for (i32 r = 0; r < offset; ++r){
append(&string, ' ');
}
append_padding(&string, ' ', 40);
append(&string, input_event->consumer);
}
gui_do_text_field(target, string, empty_str);
}
}break;
case DBG_Memory:
{
Partition *part = &models->mem.part;
General_Memory *general = &models->mem.general;
string.size = 0;
append(&string, "part memory: ");
append_int_to_str(&string, part->pos);
append(&string, "/");
append_int_to_str(&string, part->max);
gui_do_text_field(target, string, empty_str);
Bubble *bubble, *sentinel;
sentinel = &general->sentinel;
for (dll_items(bubble, sentinel)){
string.size = 0;
if (bubble->flags & MEM_BUBBLE_USED){
append(&string, " used: ");
}
else{
append(&string, " free: ");
}
append_int_to_str(&string, bubble->size);
append_padding(&string, ' ', 40);
append(&string, " type: ");
append_int_to_str(&string, bubble->type);
gui_do_text_field(target, string, empty_str);
}
}break;
}
gui_end_scrollable(target);
}break;
#endif
}

View File

@ -1153,7 +1153,7 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h,
always_give_to_user = 1;
session->suggested_max_y =
(f32)(session->scrollable_items_bottom -
session->full_rect.y1 * .5f);
(session->full_rect.y0 + session->full_rect.y1)*.5f);
if (session->suggested_max_y < 0){
session->suggested_max_y = 0;
}