#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <mono/metadata/class.h>
#include <mono/metadata/tabledefs.h>
#include <mono/metadata/tokentype.h>
{NULL, NULL}
};
-void
-mono_debug_open_assembly_stabs (AssemblyDebugInfo* info)
-{
-}
-
-void
-mono_debug_close_assembly_stabs (AssemblyDebugInfo* info)
-{
-}
-
static void
-write_method_stabs (AssemblyDebugInfo *info, DebugMethodInfo *minfo)
+write_method_stabs (MonoDebugHandle *debug, MonoDebugMethodInfo *minfo)
{
int i;
- MonoMethod *method = minfo->method_info.method;
+ DebugMethodInfo *priv = minfo->user_data;
+ MonoMethod *method = minfo->method;
MonoClass *klass = method->klass;
MonoMethodSignature *sig = method->signature;
char **names = g_new (char*, sig->param_count);
+ gchar *source_file;
+
+ if (!minfo->jit)
+ return;
+
+ source_file = g_ptr_array_index (debug->source_files, priv->source_file);
- fprintf (info->f, ".stabs \"%s:F(0,%d)\",36,0,%d,%p\n", minfo->name, sig->ret->type,
- minfo->start_line, minfo->method_info.code_start);
+ fprintf (debug->f, ".stabs \"%s\",100,0,0,0\n", source_file);
+
+ fprintf (debug->f, ".stabs \"%s:F(0,%d)\",36,0,%d,%p\n", priv->name, sig->ret->type,
+ priv->start_line, minfo->jit->code_start);
/* params */
mono_method_get_param_names (method, (const char **)names);
if (sig->hasthis)
- fprintf (info->f, ".stabs \"this:p(0,%d)=(0,%d)\",160,0,%d,%d\n",
- info->next_idx++, klass->byval_arg.type, minfo->start_line,
- minfo->method_info.this_offset);
- for (i = 0; i < minfo->method_info.num_params; i++) {
- int stack_offset = minfo->method_info.param_offsets [i];
-
- fprintf (info->f, ".stabs \"%s:p(0,%d)=(0,%d)\",160,0,%d,%d\n",
- names [i], info->next_idx++, sig->params [i]->type,
- minfo->start_line, stack_offset);
+ fprintf (debug->f, ".stabs \"this:p(0,%d)=(0,%d)\",160,0,%d,%d\n",
+ debug->next_idx++, klass->byval_arg.type, priv->start_line,
+ minfo->jit->this_var->offset);
+ for (i = 0; i < minfo->jit->num_params; i++) {
+ int stack_offset = minfo->jit->params [i].offset;
+
+ fprintf (debug->f, ".stabs \"%s:p(0,%d)=(0,%d)\",160,0,%d,%d\n",
+ names [i], debug->next_idx++, sig->params [i]->type,
+ priv->start_line, stack_offset);
}
/* local vars */
- for (i = 0; i < minfo->method_info.num_locals; ++i) {
+ for (i = 0; i < minfo->jit->num_locals; ++i) {
MonoMethodHeader *header = ((MonoMethodNormal*)method)->header;
- int stack_offset = minfo->method_info.local_offsets [i];
+ int stack_offset = minfo->jit->locals [i].offset;
- fprintf (info->f, ".stabs \"local_%d:(0,%d)=(0,%d)\",128,0,%d,%d\n",
- i, info->next_idx++, header->locals [i]->type, minfo->start_line, stack_offset);
+ fprintf (debug->f, ".stabs \"local_%d:(0,%d)=(0,%d)\",128,0,%d,%d\n",
+ i, debug->next_idx++, header->locals [i]->type, priv->start_line, stack_offset);
}
- if (minfo->line_numbers) {
- fprintf (info->f, ".stabn 68,0,%d,%d\n", minfo->start_line, 0);
- fprintf (info->f, ".stabn 68,0,%d,%d\n", minfo->first_line, minfo->prologue_end_offset);
+ if (minfo->jit && minfo->jit->line_numbers) {
+ fprintf (debug->f, ".stabn 68,0,%d,%d\n", priv->start_line, 0);
+ fprintf (debug->f, ".stabn 68,0,%d,%d\n", priv->first_line,
+ minfo->jit->prologue_end);
- for (i = 1; i < minfo->line_numbers->len; i++) {
- DebugLineNumberInfo *lni = g_ptr_array_index (minfo->line_numbers, i);
+ for (i = 1; i < minfo->jit->line_numbers->len; i++) {
+ MonoDebugLineNumberEntry lne = g_array_index (
+ minfo->jit->line_numbers, MonoDebugLineNumberEntry, i);
- fprintf (info->f, ".stabn 68,0,%d,%d\n", lni->line,
- lni->address - minfo->method_info.code_start);
+ fprintf (debug->f, ".stabn 68,0,%d,%d\n", lne.line, lne.address);
}
- fprintf (info->f, ".stabn 68,0,%d,%d\n", minfo->last_line, minfo->epilogue_begin_offset);
+ fprintf (debug->f, ".stabn 68,0,%d,%d\n", priv->last_line,
+ minfo->jit->epilogue_begin);
}
/* end of function */
- fprintf (info->f, ".stabs \"\",36,0,0,%d\n", minfo->method_info.code_size);
+ fprintf (debug->f, ".stabs \"\",36,0,0,%d\n", minfo->jit->code_size);
g_free (names);
- fflush (info->f);
+ fflush (debug->f);
}
static void
}
static void
-write_class_stabs (AssemblyDebugInfo *info, MonoClass *klass, int idx)
+write_method_func_1 (gpointer key, gpointer value, gpointer user_data)
+{
+ AssemblyDebugInfo *info = (AssemblyDebugInfo *) value;
+
+ g_hash_table_foreach (info->methods, write_method_func, user_data);
+}
+
+static void
+write_class_stabs (MonoDebugHandle *debug, MonoClass *klass, int idx)
{
char *name;
int i;
/* output enums ...*/
if (klass->enumtype) {
name = g_strdup_printf ("%s%s%s", klass->name_space, klass->name_space [0]? "_": "", klass->name);
- fprintf (info->f, ".stabs \"%s:T%d=e", name, ++info->next_idx);
+ fprintf (debug->f, ".stabs \"%s:T%d=e", name, ++debug->next_idx);
g_free (name);
for (i = 0; i < klass->field.count; ++i) {
if (klass->fields [i].type->attrs & FIELD_ATTRIBUTE_LITERAL) {
get_enumvalue (klass, klass->field.first + i, buf);
- fprintf (info->f, "%s_%s=%s,", klass->name, klass->fields [i].name, buf);
+ fprintf (debug->f, "%s_%s=%s,", klass->name, klass->fields [i].name, buf);
}
}
- fprintf (info->f, ";\",128,0,0,0\n");
+ fprintf (debug->f, ";\",128,0,0,0\n");
}
- fflush (info->f);
+ fflush (debug->f);
}
static void
}
void
-mono_debug_write_assembly_stabs (AssemblyDebugInfo* info)
+mono_debug_write_stabs (MonoDebugHandle *debug)
{
- char *buf;
+ gchar *source_file;
int i;
- if (!(info->f = fopen (info->filename, "w")))
+ if (!(debug->f = fopen (debug->filename, "w"))) {
+ g_warning ("Can't create stabs file `%s': %s", debug->filename, g_strerror (errno));
return;
+ }
+
+ source_file = g_ptr_array_index (debug->source_files, 0);
- fprintf (info->f, ".stabs \"%s.il\",100,0,0,0\n", info->name);
+ fprintf (debug->f, ".stabs \"%s\",100,0,0,0\n", source_file);
for (i = 0; base_types [i].name; ++i) {
if (! base_types [i].spec)
continue;
- fprintf (info->f, ".stabs \"%s:t(0,%d)=", base_types [i].name, i);
+ fprintf (debug->f, ".stabs \"%s:t(0,%d)=", base_types [i].name, i);
if (base_types [i].spec [0] == ';') {
- fprintf (info->f, "r(0,%d)%s\"", i, base_types [i].spec);
+ fprintf (debug->f, "r(0,%d)%s\"", i, base_types [i].spec);
} else {
- fprintf (info->f, "%s\"", base_types [i].spec);
+ fprintf (debug->f, "%s\"", base_types [i].spec);
}
- fprintf (info->f, ",128,0,0,0\n");
+ fprintf (debug->f, ",128,0,0,0\n");
}
- g_hash_table_foreach (info->methods, write_method_func, info);
+ g_hash_table_foreach (debug->images, write_method_func_1, debug);
- g_hash_table_foreach (info->type_hash, write_class, info);
+ g_hash_table_foreach (debug->type_hash, write_class, debug);
- fclose (info->f);
- info->f = NULL;
+ fclose (debug->f);
+ debug->f = NULL;
- /* yes, it's completely unsafe */
- buf = g_strdup_printf ("as %s -o /tmp/%s.o", info->filename, info->name);
- system (buf);
- g_free (buf);
+ if (!(debug->flags & MONO_DEBUG_FLAGS_DONT_ASSEMBLE)) {
+ char *buf;
+
+ /* yes, it's completely unsafe */
+ buf = g_strdup_printf ("as %s -o %s", debug->filename, debug->objfile);
+ system (buf);
+ g_free (buf);
+ }
}