2002-08-19 Dick Porter <dick@ximian.com>
[mono.git] / mono / jit / debug-dwarf2-plus.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <errno.h>
4 #include <sys/stat.h>
5 #include <mono/metadata/class.h>
6 #include <mono/metadata/debug-symfile.h>
7 #include <mono/jit/codegen.h>
8 #include <mono/jit/debug.h>
9
10 #include "debug-private.h"
11
12 static MonoDebugMethodInfo *
13 method_info_func (MonoDebugSymbolFile *symfile, guint32 token, gpointer user_data)
14 {
15         AssemblyDebugInfo *info = user_data;
16         MonoMethod *method;
17         DebugMethodInfo *minfo;
18
19         method = g_hash_table_lookup (info->image->method_cache, GINT_TO_POINTER (token));
20         if (!method)
21                 return NULL;
22
23         minfo = g_hash_table_lookup (info->handle->methods, method);
24
25         return (MonoDebugMethodInfo *) minfo;
26 }
27
28 void
29 mono_debug_open_assembly_dwarf2_plus (AssemblyDebugInfo *info)
30 {
31         if (!(info->handle->flags & MONO_DEBUG_FLAGS_DONT_ASSEMBLE)) {
32                 struct stat stata, statb;
33
34                 if (stat (info->filename, &stata)) {
35                         g_warning ("cannot access assembly file (%s): %s",
36                                    info->filename, g_strerror (errno));
37                         return;
38                 }
39
40                 /* If the stat() failed or the file is older. */
41                 if (stat (info->objfile, &statb) || (statb.st_mtime < stata.st_mtime)) {
42                         char *buf;
43
44                         buf = g_strdup_printf ("as %s -o %s", info->filename, info->objfile);
45                         system (buf);
46                         g_free (buf);
47                 }
48         }
49
50         if (!(info->handle->flags & MONO_DEBUG_FLAGS_DONT_PRECOMPILE))
51                 mono_jit_compile_image (info->image, FALSE);
52
53         info->symfile = mono_debug_open_symbol_file (info->image, info->objfile, TRUE);
54 }
55
56 void
57 mono_debug_close_assembly_dwarf2_plus (AssemblyDebugInfo *info)
58 {
59         if (info->symfile)
60                 mono_debug_close_symbol_file (info->symfile);
61 }
62
63 void
64 mono_debug_write_assembly_dwarf2_plus (AssemblyDebugInfo *info)
65 {
66         if (info->symfile)
67                 mono_debug_update_symbol_file (info->symfile, method_info_func, info);
68 }