diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-05-04 18:50:00 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-05-04 18:50:00 -0400 |
commit | 47f5f487159e63723ae431fa6d55bbc08ad443fb (patch) | |
tree | c7733cb28b37945b0aca5361ac8fa2e57417d801 /base.h | |
parent | 6fb841710498e1b854204287e6a8c7b2a0bd3b5c (diff) |
search UI
Diffstat (limited to 'base.h')
-rw-r--r-- | base.h | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -0,0 +1,81 @@ +// types and stuff needed everywhere + +#include <gtk/gtk.h> +#include <fcntl.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <inttypes.h> +#include <unistd.h> +#include <assert.h> +#include <ctype.h> +#include <wctype.h> + +typedef pid_t PID; +typedef uint64_t Address; +#define SCNxADDR SCNx64 +#define PRIdADDR PRId64 +#define PRIxADDR PRIx64 + +typedef enum { + TYPE_U8, + TYPE_S8, + TYPE_U16, + TYPE_S16, + TYPE_U32, + TYPE_S32, + TYPE_U64, + TYPE_S64, + TYPE_ASCII, + TYPE_UTF16, + TYPE_UTF32, + TYPE_F32, + TYPE_F64 +} DataType; + +typedef enum { + SEARCH_ENTER_VALUE, + SEARCH_SAME_DIFFERENT +} SearchType; + +// a memory map +typedef struct { + Address lo, size; +} Map; + +typedef struct { + GtkWindow *window; + GtkBuilder *builder; + bool stop_while_accessing_memory; + long editing_memory; // index of memory value being edited, or -1 if none is + PID pid; + Address total_memory; // total amount of memory used by process, in bytes + Map *maps; + Address memory_view_address; + uint32_t memory_view_entries; // # of entries to show + unsigned nmaps; + DataType data_type; + SearchType search_type; +} State; + +static void display_dialog_box_nofmt(State *state, GtkMessageType type, char const *message) { + GtkWidget *box = gtk_message_dialog_new(state->window, + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + type, GTK_BUTTONS_OK, "%s", message); + // make sure dialog box is closed when OK is clicked. + g_signal_connect_swapped(box, "response", G_CALLBACK(gtk_widget_destroy), box); + gtk_widget_show_all(box); +} + +// this is a macro so we get -Wformat warnings +#define display_dialog_box(state, type, fmt, ...) do { \ + char _buf[1024]; \ + snprintf(_buf, sizeof _buf, fmt, __VA_ARGS__); \ + display_dialog_box_nofmt(state, type, _buf); \ +} while (0) +#define display_error(state, fmt, ...) display_dialog_box(state, GTK_MESSAGE_ERROR, fmt, __VA_ARGS__) +#define display_info(state, fmt, ...) display_dialog_box(state, GTK_MESSAGE_INFO, fmt, __VA_ARGS__) +#define display_info_nofmt(state, message) display_dialog_box_nofmt(state, GTK_MESSAGE_INFO, message) + + |