summaryrefslogtreecommitdiff
path: root/src/analysis/line_code.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/line_code.c')
-rw-r--r--src/analysis/line_code.c136
1 files changed, 44 insertions, 92 deletions
diff --git a/src/analysis/line_code.c b/src/analysis/line_code.c
index 697dd7d..4ceabec 100644
--- a/src/analysis/line_code.c
+++ b/src/analysis/line_code.c
@@ -61,8 +61,8 @@ static void g_code_line_init(GCodeLine *);
/* Met à jour le nombre d'octets maximal par instruction. */
void g_code_line_get_binary_len(GCodeLine *, off_t *);
-/* Met à jour la ligne de représentation de code. */
-void g_code_line_refresh_markup(GCodeLine *, MainRendering);
+/* Ajoute à un texte GTK le contenu de la ligne de code. */
+static void g_code_line_add_to_gtk_buffer(GCodeLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, gint [SAR_COUNT]);
@@ -103,14 +103,18 @@ static void g_code_line_class_init(GCodeLineClass *klass)
static void g_code_line_init(GCodeLine *line)
{
- GRenderingLine *parent; /* Instance parente */
+ GContentExporter *exporter_parent; /* Instance parente #1 */
+ GRenderingLine *line_parent; /* Instance parente #2 */
- parent = G_RENDERING_LINE(line);
+ exporter_parent = G_CONTENT_EXPORTER(line);
- parent->type = RLT_CODE;
+ exporter_parent->add_to_gtk_buffer = (add_to_gtk_buffer_fc)g_code_line_add_to_gtk_buffer;
- parent->get_bin_len = (get_bin_len_fc)g_code_line_get_binary_len;
- parent->refresh_markup = (refresh_markup_fc)g_code_line_refresh_markup;
+ line_parent = G_RENDERING_LINE(line);
+
+ line_parent->type = RLT_CODE;
+
+ line_parent->get_bin_len = (get_bin_len_fc)g_code_line_get_binary_len;
}
@@ -143,8 +147,11 @@ void g_code_line_get_binary_len(GCodeLine *line, off_t *blen)
* *
* Paramètres : line = ligne de représentation à actualiser. *
* rendering = support effectif final des lignes de code. *
+* buffer = zone de texte à venir compléter. *
+* iter = point d'insertion du nouveau texte. *
+* lengths = taille des différentes composantes de la ligne. *
* *
-* Description : Met à jour la ligne de représentation de code. *
+* Description : Ajoute à un texte GTK le contenu de la ligne de code. *
* *
* Retour : - *
* *
@@ -152,68 +159,35 @@ void g_code_line_get_binary_len(GCodeLine *line, off_t *blen)
* *
******************************************************************************/
-void g_code_line_refresh_markup(GCodeLine *line, MainRendering rendering)
+static void g_code_line_add_to_gtk_buffer(GCodeLine *line, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, gint lengths[SAR_COUNT])
{
bool show_address; /* Affichage de l'adresse ? */
bool show_code; /* Affichage du code brut ? */
- size_t len; /* Taille du contenu */
- char *content; /* Contenu réellement imprimé */
+ MemoryDataSize msize; /* Taille du bus d'adresses */
+ char address[VMPA_MAX_SIZE]; /* Adresse au format texte */
+ size_t len; /* Taille de l'élément inséré */
+ const bin_t *content; /* Contenu binaire global */
off_t bin_offset; /* Début de l'instruction */
off_t bin_len; /* Taille d'instruction */
- char buffer[CODE_BUFFER_LEN]; /* Zone tampon à utiliser #1 */
- char *buffer2; /* Zone tampon à utiliser #2 */
- const uint8_t *exe_content; /* Contenu binaire global */
- const off_t *max_bin_len; /* Taille de ligne max/globale */
char *bin_code; /* Tampon du code binaire */
- off_t k; /* Boucle de parcours #2 */
- off_t j; /* Boucle de parcours #1 */
+ off_t i; /* Boucle de parcours */
show_address = g_rendering_options_has_to_show_address(line->options, rendering);
show_code = g_rendering_options_has_to_show_code(line->options, rendering);
- len = strlen("<tt>") + 1;
- content = (char *)calloc(len, sizeof(char));
- strcpy(content, "<tt>");
-
- if (show_code)
- g_arch_instruction_get_location(line->instr, &bin_offset, &bin_len, NULL);
-
- /* Eventuelle adresse virtuelle */
+ /* Eventuelle adresse virtuelle ou physique */
if (show_address)
{
- switch (g_arch_processor_get_memory_size(g_rendering_options_get_processor(line->options)))
- {
- case MDS_8_BITS:
- snprintf(buffer, CODE_BUFFER_LEN,
- "<span foreground='#333333'>0x%02llx</span>",
- G_RENDERING_LINE(line)->offset);
- break;
-
- case MDS_16_BITS:
- snprintf(buffer, CODE_BUFFER_LEN,
- "<span foreground='#333333'>0x%04llx</span>",
- G_RENDERING_LINE(line)->offset);
- break;
-
- case MDS_32_BITS:
- snprintf(buffer, CODE_BUFFER_LEN,
- "<span foreground='#333333'>0x%08llx</span>",
- G_RENDERING_LINE(line)->offset);
- break;
-
- default:
- case MDS_64_BITS:
- snprintf(buffer, CODE_BUFFER_LEN,
- "<span foreground='#333333'>0x%16llx</span>",
- G_RENDERING_LINE(line)->offset);
- break;
+ msize = g_arch_processor_get_memory_size(g_rendering_options_get_processor(line->options));
- }
+ len = vmpa_to_string(G_RENDERING_LINE(line)->offset, msize, address);
- len += strlen(buffer);
- content = (char *)realloc(content, len * sizeof(char));
- strcat(content, buffer);
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter,
+ address, len, RTT_NONE);
+
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter,
+ "\t", 1, RTT_NONE);
}
@@ -221,56 +195,34 @@ void g_code_line_refresh_markup(GCodeLine *line, MainRendering rendering)
if (show_code)
{
- exe_content = g_binary_format_get_content(G_BIN_FORMAT(g_rendering_options_get_format(line->options)), NULL);
- max_bin_len = &G_RENDERING_LINE(line)->max_bin_len[rendering];
-
- bin_code = (char *)calloc(*max_bin_len + 1, sizeof(char));
+ content = g_binary_format_get_content(G_BIN_FORMAT(g_rendering_options_get_format(line->options)), NULL);
+ g_arch_instruction_get_location(line->instr, &bin_offset, &bin_len, NULL);
- k = 0;
+ bin_code = (char *)calloc(bin_len * 3, sizeof(char));
- for (j = 0; j < bin_len; j++)
+ for (i = 0; i < bin_len; i++)
{
- if ((j + 1) < bin_len)
- k += snprintf(&bin_code[j * (2 + 1)], 4, "%02hhx ", exe_content[bin_offset + j]);
+ if ((i + 1) < bin_len)
+ snprintf(&bin_code[i * (2 + 1)], 4, "%02hhx ", content[bin_offset + i]);
else
- k += snprintf(&bin_code[j * (2 + 1)], 3, "%02hhx", exe_content[bin_offset + j]);
+ snprintf(&bin_code[i * (2 + 1)], 3, "%02hhx", content[bin_offset + i]);
}
- for (; k < *max_bin_len; k++)
- snprintf(&bin_code[k], 2, " ");
-
- if (show_address) len += strlen("\t");
- len += strlen(bin_code);
- content = (char *)realloc(content, len * sizeof(char));
- if (show_address) strcat(content, "\t");
- strcat(content, bin_code);
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter,
+ bin_code, bin_len * 3 - 1, RTT_RAW_CODE);
free(bin_code);
+ g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter,
+ "\t", 1, RTT_NONE);
+
}
/* Instruction proprement dite */
- buffer2 = g_arch_instruction_get_text(line->instr, g_rendering_options_get_format(line->options), ASX_INTEL/*FIXME*/);
-
- if (show_address || show_code) len += strlen("\t");
- len += strlen(buffer2);
-
- content = (char *)realloc(content, len * sizeof(char));
- if (show_address || show_code) strcat(content, "\t");
- strcat(content, buffer2);
-
- free(buffer2);
-
- /* Finalisation */
-
- len += strlen("</tt>");
- content = (char *)realloc(content, len * sizeof(char));
- strcat(content, "</tt>");
-
- pango_layout_set_markup(G_RENDERING_LINE(line)->layout[rendering], content, len - 1);
-
- free(content);
+ g_content_exporter_add_arch_to_gtk_buffer(G_CONTENT_EXPORTER(line->instr),
+ g_rendering_options_get_format(line->options),
+ ASX_INTEL/*FIXME*/, buffer, iter);
}