+gboolean rettrue(gpointer key, gpointer value, gpointer user_data)
+{
+ return TRUE;
+}
+
+static guint check_expand(nb, id)
+{
+ if(likely(nb > id))
+ return nb;
+ else
+ return max(id + 1, nb * 2);
+}
+
+static void expand_name_table(LttvTraceState *ts, GQuark **table,
+ guint nb, guint new_nb)
+{
+ /* Expand an incomplete table */
+ GQuark *old_table = *table;
+ *table = g_new(GQuark, new_nb);
+ memcpy(*table, old_table, nb * sizeof(GQuark));
+}
+
+static void fill_name_table(LttvTraceState *ts, GQuark *table, guint nb,
+ guint new_nb, const char *def_string)
+{
+ guint i;
+ GString *fe_name = g_string_new("");
+ for(i = nb; i < new_nb; i++) {
+ g_string_printf(fe_name, "%s %d", def_string, i);
+ table[i] = g_quark_from_string(fe_name->str);
+ }
+ g_string_free(fe_name, TRUE);
+}
+
+static void expand_syscall_table(LttvTraceState *ts, int id)
+{
+ guint new_nb = check_expand(ts->nb_syscalls, id);
+ if(likely(new_nb == ts->nb_syscalls))
+ return;
+ expand_name_table(ts, &ts->syscall_names, ts->nb_syscalls, new_nb);
+ fill_name_table(ts, ts->syscall_names, ts->nb_syscalls, new_nb, "syscall");
+ /* Update the table size */
+ ts->nb_syscalls = new_nb;
+}
+
+static void expand_trap_table(LttvTraceState *ts, int id)
+{
+ guint new_nb = check_expand(ts->nb_traps, id);
+ guint i;
+ if(likely(new_nb == ts->nb_traps))
+ return;
+ expand_name_table(ts, &ts->trap_names, ts->nb_traps, new_nb);
+ fill_name_table(ts, ts->trap_names, ts->nb_traps, new_nb, "trap");
+ /* Update the table size */
+ ts->nb_traps = new_nb;
+
+ LttvTrapState *old_table = ts->trap_states;
+ ts->trap_states = g_new(LttvTrapState, new_nb);
+ memcpy(ts->trap_states, old_table,
+ ts->nb_traps * sizeof(LttvTrapState));
+ for(i = ts->nb_traps; i < new_nb; i++)
+ ts->trap_states[i].running = 0;
+}
+
+static void expand_irq_table(LttvTraceState *ts, int id)
+{
+ guint new_nb = check_expand(ts->nb_irqs, id);
+ guint i;
+ if(likely(new_nb == ts->nb_irqs))
+ return;
+ expand_name_table(ts, &ts->irq_names, ts->nb_irqs, new_nb);
+ fill_name_table(ts, ts->irq_names, ts->nb_irqs, new_nb, "irq");
+
+ LttvIRQState *old_table = ts->irq_states;
+ ts->irq_states = g_new(LttvIRQState, new_nb);
+ memcpy(ts->irq_states, old_table, ts->nb_irqs * sizeof(LttvIRQState));
+ for(i = ts->nb_irqs; i < new_nb; i++) {
+ ts->irq_states[i].mode_stack = g_array_new(FALSE, FALSE, sizeof(LttvIRQMode));
+ }