diff -uprN -x '*~' gdb-6.8/gdb/buildsym.c gdb-6.8-vala/gdb/buildsym.c --- gdb-6.8/gdb/buildsym.c 2008-01-01 23:53:09.000000000 +0100 +++ gdb-6.8-vala/gdb/buildsym.c 2008-08-16 16:38:36.000000000 +0100 @@ -658,14 +658,14 @@ start_subfile (char *name, char *dirname /* If the filename of this subfile ends in .C, then change the language of any pending subfiles from C to C++. We also accept any other C++ suffixes accepted by deduce_language_from_filename. */ - /* Likewise for f2c. */ + /* Likewise for f2c and Vala. */ if (subfile->name) { struct subfile *s; enum language sublang = deduce_language_from_filename (subfile->name); - if (sublang == language_cplus || sublang == language_fortran) + if (sublang == language_cplus || sublang == language_fortran || sublang == language_vala) for (s = subfiles; s != NULL; s = s->next) if (s->language == language_c) s->language = sublang; @@ -675,7 +675,8 @@ start_subfile (char *name, char *dirname if (subfile->language == language_c && subfile->next != NULL && (subfile->next->language == language_cplus - || subfile->next->language == language_fortran)) + || subfile->next->language == language_fortran + || subfile->next->language == language_vala)) { subfile->language = subfile->next->language; } diff -uprN -x '*~' gdb-6.8/gdb/c-lang.c gdb-6.8-vala/gdb/c-lang.c --- gdb-6.8/gdb/c-lang.c 2008-02-05 23:17:40.000000000 +0100 +++ gdb-6.8-vala/gdb/c-lang.c 2008-08-16 16:38:36.000000000 +0100 @@ -35,13 +35,12 @@ #include "cp-support.h" extern void _initialize_c_language (void); -static void c_emit_char (int c, struct ui_file * stream, int quoter); /* Print the character C on STREAM as part of the contents of a literal string whose delimiter is QUOTER. Note that that format for printing characters and strings is language specific. */ -static void +void c_emit_char (int c, struct ui_file *stream, int quoter) { const char *escape; diff -uprN -x '*~' gdb-6.8/gdb/c-lang.h gdb-6.8-vala/gdb/c-lang.h --- gdb-6.8/gdb/c-lang.h 2008-01-01 23:53:09.000000000 +0100 +++ gdb-6.8-vala/gdb/c-lang.h 2008-08-16 16:38:36.000000000 +0100 @@ -52,6 +52,8 @@ extern void c_printstr (struct ui_file * unsigned int length, int width, int force_ellipses); +extern void c_emit_char (int, struct ui_file *, int); + extern void scan_macro_expansion (char *expansion); extern int scanning_macro_expansion (void); extern void finished_macro_expansion (void); diff -uprN -x '*~' gdb-6.8/gdb/defs.h gdb-6.8-vala/gdb/defs.h --- gdb-6.8/gdb/defs.h 2008-01-18 18:07:39.000000000 +0100 +++ gdb-6.8-vala/gdb/defs.h 2008-08-16 16:38:36.000000000 +0100 @@ -182,6 +182,7 @@ enum language language_pascal, /* Pascal */ language_ada, /* Ada */ language_scm, /* Guile Scheme */ + language_vala, /* Vala */ language_minimal, /* All other languages, minimal support only */ nr_languages }; diff -uprN -x '*~' gdb-6.8/gdb/dwarf2read.c gdb-6.8-vala/gdb/dwarf2read.c --- gdb-6.8/gdb/dwarf2read.c 2008-03-10 15:18:10.000000000 +0100 +++ gdb-6.8-vala/gdb/dwarf2read.c 2008-08-16 16:38:36.000000000 +0100 @@ -7255,7 +7255,7 @@ new_symbol (struct die_info *die, struct memset (sym, 0, sizeof (struct symbol)); /* Cache this symbol's name and the name's demangled form (if any). */ - SYMBOL_LANGUAGE (sym) = cu->language; + SYMBOL_LANGUAGE (sym) = current_subfile->language; SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); /* Default assumptions. diff -uprN -x '*~' gdb-6.8/gdb/eval.c gdb-6.8-vala/gdb/eval.c --- gdb-6.8/gdb/eval.c 2008-02-04 01:23:04.000000000 +0100 +++ gdb-6.8-vala/gdb/eval.c 2008-08-16 16:38:36.000000000 +0100 @@ -2079,7 +2079,10 @@ evaluate_subexp_standard (struct type *e case OP_THIS: (*pos) += 1; - return value_of_this (1); + if (current_language->la_value_of_this) + return current_language->la_value_of_this (1); + else + error (_("internal error : `this' is not defined for current language")); case OP_OBJC_SELF: (*pos) += 1; diff -uprN -x '*~' gdb-6.8/gdb/gdbtypes.c gdb-6.8-vala/gdb/gdbtypes.c --- gdb-6.8/gdb/gdbtypes.c 2008-02-03 23:13:29.000000000 +0100 +++ gdb-6.8-vala/gdb/gdbtypes.c 2008-08-17 18:25:59.000000000 +0100 @@ -38,6 +38,7 @@ #include "cp-abi.h" #include "gdb_assert.h" #include "hashtab.h" +#include "vala-lang.h" /* These variables point to the objects representing the predefined C data types. */ @@ -1261,6 +1262,21 @@ lookup_struct_elt_type (struct type *typ } } + if (current_language->la_language == language_vala) + { + struct field* privfields; + int nfields; + privfields = vala_type_get_private_fields (type, &nfields); + for (i = 0; i < nfields; i++) + { + char *t_field_name = privfields[i].name; + if (t_field_name && (strcmp_iw (t_field_name, name) == 0)) + { + return privfields[i].type; + } + } + } + /* OK, it's not in this class. Recursively check the baseclasses. */ for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) { diff -uprN -x '*~' gdb-6.8/gdb/linespec.c gdb-6.8-vala/gdb/linespec.c --- gdb-6.8/gdb/linespec.c 2008-01-01 23:53:11.000000000 +0100 +++ gdb-6.8-vala/gdb/linespec.c 2008-08-16 16:38:36.000000000 +0100 @@ -33,6 +33,7 @@ #include "parser-defs.h" #include "block.h" #include "objc-lang.h" +#include "vala-lang.h" #include "linespec.h" #include "exceptions.h" #include "language.h" @@ -182,7 +183,7 @@ total_number_of_methods (struct type *ty CHECK_TYPEDEF (type); if (TYPE_CPLUS_SPECIFIC (type) == NULL) - return 0; + return 1; /* to be used by vala */ count = TYPE_NFN_FIELDS_TOTAL (type); for (n = 0; n < TYPE_N_BASECLASSES (type); n++) @@ -1380,6 +1381,7 @@ lookup_prefix_sym (char **argptr, char * { char *p1; char *copy; + struct symbol* sym; /* Extract the class name. */ p1 = p; @@ -1398,8 +1400,17 @@ lookup_prefix_sym (char **argptr, char * /* At this point p1->"::inA::fun", p->"inA::fun" copy->"AAA", argptr->"inA::fun" */ - return lookup_symbol (copy, 0, STRUCT_DOMAIN, 0, + sym = lookup_symbol (copy, 0, STRUCT_DOMAIN, 0, (struct symtab **) NULL); + if (sym == NULL) + { + /* In Vala, a class ClassName will give a struct _ClassName */ + char* _name = concat ("_", copy, NULL); + sym = lookup_symbol (_name, 0, STRUCT_DOMAIN, 0, + (struct symtab **) NULL); + xfree (_name); + } + return sym; } /* This finds the method COPY in the class whose type is T and whose @@ -1450,6 +1461,20 @@ find_method (int funfirstline, char ***c { char *tmp; + /* try looking up a vala method*/ + tmp = vala_member_name(VALA_TYPE_NAME(t), copy); + sym = lookup_symbol (tmp, NULL, VAR_DOMAIN, NULL, NULL); + xfree (tmp); + if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) + { + values.sals = (struct symtab_and_line *) + xmalloc (sizeof (struct symtab_and_line)); + values.nelts = 1; + values.sals[0] = find_function_start_sal (sym, + funfirstline); + return values; + } + if (is_operator_name (copy)) { tmp = (char *) alloca (strlen (copy + 3) + 9); diff -uprN -x '*~' gdb-6.8/gdb/Makefile.in gdb-6.8-vala/gdb/Makefile.in --- gdb-6.8/gdb/Makefile.in 2008-03-17 13:15:08.000000000 +0100 +++ gdb-6.8-vala/gdb/Makefile.in 2008-08-17 13:21:21.000000000 +0100 @@ -631,6 +631,7 @@ SFILES = ada-exp.y ada-lang.c ada-typepr typeprint.c \ ui-out.c utils.c ui-file.h ui-file.c \ user-regs.c \ + vala-lang.c vala-print.c\ valarith.c valops.c valprint.c value.c varobj.c vec.c \ wrapper.c \ xml-tdesc.c xml-support.c @@ -1056,6 +1057,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $ jv-lang.o jv-valprint.o jv-typeprint.o \ m2-lang.o p-lang.o p-typeprint.o p-valprint.o \ scm-exp.o scm-lang.o scm-valprint.o \ + vala-lang.o vala-print.o\ sentinel-frame.o \ complaints.o typeprint.o \ ada-typeprint.o c-typeprint.o f-typeprint.o m2-typeprint.o \ @@ -2919,6 +2921,16 @@ v850-tdep.o: v850-tdep.c $(defs_h) $(fra $(frame_unwind_h) $(dwarf2_frame_h) $(gdbtypes_h) $(inferior_h) \ $(gdb_string_h) $(gdb_assert_h) $(gdbcore_h) $(arch_utils_h) \ $(regcache_h) $(dis_asm_h) $(osabi_h) +vala-lang.o: vala-lang.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \ + $(parser_defs_h) $(language_h) $(gdbtypes_h) $(symtab_h) \ + $(symfile_h) $(objfiles_h) $(gdb_string_h) $(value_h) $(c_lang_h) \ + $(jv_lang_h) $(gdbcore_h) $(block_h) $(demangle_h) $(dictionary_h) \ + $(gdb_assert_h) +vala-print.o: vala-print.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \ + $(parser_defs_h) $(language_h) $(gdbtypes_h) $(symtab_h) \ + $(symfile_h) $(objfiles_h) $(gdb_string_h) $(value_h) $(c_lang_h) \ + $(jv_lang_h) $(gdbcore_h) $(block_h) $(demangle_h) $(dictionary_h) \ + $(gdb_assert_h) valarith.o: valarith.c $(defs_h) $(value_h) $(symtab_h) $(gdbtypes_h) \ $(expression_h) $(target_h) $(language_h) $(gdb_string_h) \ $(doublest_h) $(dfp_h) $(infcall_h) diff -uprN -x '*~' gdb-6.8/gdb/stack.c gdb-6.8-vala/gdb/stack.c --- gdb-6.8/gdb/stack.c 2008-03-17 16:06:24.000000000 +0100 +++ gdb-6.8-vala/gdb/stack.c 2008-08-16 16:38:36.000000000 +0100 @@ -43,6 +43,7 @@ #include "regcache.h" #include "solib.h" #include "valprint.h" +#include "vala-lang.h" #include "gdb_assert.h" #include @@ -1376,13 +1377,17 @@ print_block_frame_locals (struct block * case LOC_STATIC: case LOC_BASEREG: case LOC_COMPUTED: - values_printed = 1; - for (j = 0; j < num_tabs; j++) - fputs_filtered ("\t", stream); - fputs_filtered (SYMBOL_PRINT_NAME (sym), stream); - fputs_filtered (" = ", stream); - print_variable_value (sym, frame, stream); - fprintf_filtered (stream, "\n"); + if (current_language->la_language != language_vala || + strncmp (SYMBOL_PRINT_NAME (sym), "_tmp", 4)) + { + values_printed = 1; + for (j = 0; j < num_tabs; j++) + fputs_filtered ("\t", stream); + fputs_filtered (SYMBOL_PRINT_NAME (sym), stream); + fputs_filtered (" = ", stream); + print_variable_value (sym, frame, stream); + fprintf_filtered (stream, "\n"); + } break; default: diff -uprN -x '*~' gdb-6.8/gdb/symfile.c gdb-6.8-vala/gdb/symfile.c --- gdb-6.8/gdb/symfile.c 2008-01-29 23:47:20.000000000 +0100 +++ gdb-6.8-vala/gdb/symfile.c 2008-08-16 16:38:36.000000000 +0100 @@ -2693,6 +2693,7 @@ init_filename_language_table (void) add_filename_language (".ads", language_ada); add_filename_language (".a", language_ada); add_filename_language (".ada", language_ada); + add_filename_language (".vala", language_vala); } } diff -uprN -x '*~' gdb-6.8/gdb/symtab.c gdb-6.8-vala/gdb/symtab.c --- gdb-6.8/gdb/symtab.c 2008-02-05 23:17:40.000000000 +0100 +++ gdb-6.8-vala/gdb/symtab.c 2008-08-17 14:38:35.000000000 +0100 @@ -41,6 +41,7 @@ #include "objc-lang.h" #include "ada-lang.h" #include "p-lang.h" +#include "vala-lang.h" #include "hashtab.h" @@ -1203,7 +1204,7 @@ lookup_symbol_aux (const char *name, con { struct value *v = langdef->la_value_of_this (0); - if (v && check_field (v, name)) + if (v && (check_field (v, name) || vala_check_priv_field (v, name))) { *is_a_field_of_this = 1; if (symtab != NULL) diff -uprN -x '*~' gdb-6.8/gdb/vala-lang.c gdb-6.8-vala/gdb/vala-lang.c --- gdb-6.8/gdb/vala-lang.c 1970-01-01 00:00:00.000000000 +0000 +++ gdb-6.8-vala/gdb/vala-lang.c 2008-08-18 16:55:46.000000000 +0100 @@ -0,0 +1,376 @@ +#include "defs.h" +#include "symtab.h" +#include "gdbtypes.h" +#include "expression.h" +#include "parser-defs.h" +#include "language.h" +#include "gdb_string.h" +#include "value.h" +#include "target.h" +#include "infcall.h" +#include "vala-lang.h" +#include "c-lang.h" +#include "jv-lang.h" +#include + +static CORE_ADDR vala_skip_trampoline (struct frame_info *, CORE_ADDR); +static struct value *vala_value_of_this (int); +static struct type*vala_lookup_transparent_type (const char*); +static char *vala_demangle (const char *, int); + + +/* defined in c-lang.c */ +extern const struct op_print c_op_print_tab[]; + + +const struct language_defn vala_language_defn = { + "vala", /* Language name */ + language_vala, + range_check_off, + type_check_off, + case_sensitive_on, + array_row_major, + &exp_descriptor_standard, + java_parse, + java_error, + null_post_parser, + c_printchar, /* Print a character constant */ + c_printstr, /* Function to print string constant */ + c_emit_char, /* Function to print a single character */ + vala_print_type, /* Print a type using appropriate syntax */ + vala_val_print, /* Print a value using appropriate syntax */ + vala_value_print, /* Print a top-level value */ + vala_skip_trampoline, /* Language specific skip_trampoline */ + vala_value_of_this, /* value_of_this */ + basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ + vala_lookup_transparent_type, /* lookup_transparent_type */ + vala_demangle, /* Language specific symbol demangler */ + NULL, /* Language specific class name */ + c_op_print_tab, /* expression operators for printing */ + 1, /* c-style arrays */ + 0, /* String lower bound */ + default_word_break_characters, + default_make_symbol_completion_list, + c_language_arch_info, + default_print_array_index, + default_pass_by_reference, + LANG_MAGIC +}; + +extern void +_initialize_vala_language (void) +{ + add_language (&vala_language_defn); +} + + +/* This method does the inverse of what vala_member_name does. Unfortunately, + there are 3 possible inverses for name : Name, NAme, and NAME. I'm testing + only for the first one. + Another solution is to get the name from GType, but that doesn't seem to work */ +static char * +vala_demangle (const char *mangled, int options) +{ + /* doesn't seem to work */ +#if 0 + //struct value *g_type_name = value_of_variable (lookup_symbol ("g_type_name", NULL, VAR_DOMAIN, NULL, NULL), NULL); + struct value *g_type_name = find_function_in_inferior ("g_type_name"); + + if (target_has_execution && g_type_name != NULL) + { + char* c; + struct symbol *sym = NULL; + + for (c = strchr(mangled, '_'); c != NULL; c = strchr(c + 1, '_')) + { + //printf ("c = %s\n", c); + if (streq (c, "_it") || streq (c, "_collection")) + return NULL; + else + { + char *get_type = strndup (mangled, c - mangled); + get_type = reconcat (get_type, get_type, "_get_type", NULL); + + sym = lookup_symbol (get_type, NULL, VAR_DOMAIN, NULL, NULL); + xfree (get_type); + + if (sym != NULL) + { + struct type *type = SYMBOL_TYPE(sym); + if (streq (TYPE_NAME(TYPE_TARGET_TYPE(type)), "GType")) + { + // printf ("%s\n", SYMBOL_NATURAL_NAME(sym)); + break; + } + } + } + } + + if (sym != NULL) + { + struct value* g_type, *get_type, *type_name; + char *name = NULL; + get_type = value_of_variable(sym, NULL); + g_type = call_function_by_hand (get_type, 0, NULL); + type_name = call_function_by_hand (g_type_name, 1, &g_type); + if (target_read_string (VALUE_ADDRESS(type_name), &name, 1024, NULL)) + return reconcat (name, name, ".", c+1, NULL); + } + return NULL; + } +#endif + + char* part; + char* class_name = strdup (""); + char* method_name; + struct type* type = NULL; + char* name; + + name = strdup (mangled); + part = strtok (name, "_"); + while (type == NULL && part != NULL) + { + part[0] = toupper (part[0]); + class_name = reconcat (class_name, class_name, part, NULL); + type = vala_lookup_transparent_type (class_name); + part = strtok (NULL, "_"); + } + xfree (class_name); + + if (type != NULL && part != NULL) + { + int creation_method = 0; + class_name = VALA_TYPE_NAME(type); + + if (streq (part, "new")) + { + /* creation method */ + creation_method = 1; + method_name = strdup (".new"); + } + else if (streq (part, "real")) + { + /* a virtual method implementation */ + part = strtok (NULL, "_"); + method_name = strdup (part); + } + else + method_name = strdup (part); + + if (part + strlen (part) < name + strlen (mangled)) + { + method_name = reconcat (method_name, method_name, creation_method ? "." : "_", + mangled + (part - name) + 1 + strlen (part), NULL); + } + + xfree (name); + //printf ("vala : demangling %s : %s.%s\n", mangled, class_name, method_name); + return reconcat (method_name, class_name, ".", method_name, NULL); + } + + xfree (name); + + return NULL; +} + +static struct value * +vala_value_of_this (int complain) +{ + struct value* self = value_of_local ("self", 0); + if (self != NULL) + return self; + + /* in overriding methods this argument is called base + * and this function may be called before it's casted */ + self = value_of_local ("base", 0); + /* FIXME: cast it*/ + if (self != NULL) + return self; + + if (complain) + error (_("`this' undefined in this context")); + + return NULL; +} + +static struct type* +vala_lookup_transparent_type (const char* name) +{ + char* _name; + struct type* type; + + type = basic_lookup_transparent_type (name); + if (type == NULL && name[0] != '_') + { + _name = concat ("_", name, NULL); + type = basic_lookup_transparent_type (_name); + xfree (_name); + } + + return type; +} + +static CORE_ADDR +vala_skip_trampoline (struct frame_info *frame, CORE_ADDR pc) +{ + struct symbol * func; + char* func_name; + + func = get_frame_function (frame); + if (func == NULL) + return 0; + + func_name = SYMBOL_PRINT_NAME (func); + + + /* isn't there an equivalent for g_str_has_suffix ?*/ + if (streq (func_name + (strlen(func_name) - 9), "_get_type") || + streq (func_name + (strlen(func_name) - 4), "_ref") || + streq (func_name + (strlen(func_name) - 6), "_unref")) + { + //printf ("function %s going to be skipped\n", func_name); + return frame_pc_unwind (frame); + } + + return 0; +} + +extern char* +vala_member_name (const char* type_name, const char* method_name) +{ + char *result = NULL; + int first = 1; + const char *c; + char low[2]; + low[1]='\0'; + + if (type_name[0] == 'G' && isupper(type_name[1])) + { + /* a special case for glib */ + result = strdup ("g_"); + type_name++; + } + for (c = type_name; *c != '\0'; c++) + { + if (!first && isupper (*c)) + { + /* current character is upper case and + * we're not at the beginning */ + if (!isupper (*(c-1)) || (strlen (c) >= 2 && !isupper (*(c+1)))) + { + /* previous character wasn't upper case or + * next character isn't upper case*/ + long len = strlen (result); + if (len != 1 && *(result + len - 2) != '_') + { + /* we're not creating 1 character words */ + result = reconcat (result, result, "_", NULL); + } + } + } + low[0] = tolower (*c); + result = reconcat (result, result ? result : "", low, NULL); + first = 0; + } + result = reconcat (result, result, "_", method_name, NULL); + /*printf ("class %s, method %s: %s", type_name, method_name, result);*/ + return result; +} + +extern struct value* +vala_search_method (char *name, struct value **arg1p, + struct value **args, int offset, + int *static_memfuncp, struct type *type) +{ + char *methodname; + struct symbol* methodsym; + struct value * method; + + /*char *classname; + struct type *classtype, *typeinstance; + struct value *class, *g_arg1p, *method = NULL;*/ + + methodname = vala_member_name (VALA_TYPE_NAME(type), name); + methodsym = lookup_symbol(methodname, NULL, VAR_DOMAIN, NULL, NULL); + if (methodsym != NULL) + { + /* FIXME : check if args match */ + method = value_of_variable (methodsym, NULL); + } + else if (check_field(*arg1p, "parent_instance")) + { + *arg1p = value_field (*arg1p, 0); + method = vala_search_method (name, arg1p, args, offset, static_memfuncp, + check_typedef (TYPE_FIELD(type, 0).type)); + } + +#if 0 + /* lookup virtual methods first */ + /* CLASS = (Class*) (((GTypeInstance*) arg1p)->g_class) */ + typeinstance = lookup_pointer_type (basic_lookup_transparent_type ("_GTypeInstance")); + + classname = concat (TYPE_TAG_NAME(type), "Class", NULL); + classtype = basic_lookup_transparent_type (classname); + if (classtype != NULL) + classtype = lookup_pointer_type (classtype); + else + { + classname = reconcat (classname, TYPE_TAG_NAME(type), "Iface", NULL); + classtype = basic_lookup_transparent_type (classname); + xfree(classname); + + if (classtype != NULL) + classtype = lookup_pointer_type (classtype); + else + return NULL; + } + + g_arg1p = value_cast_pointers(typeinstance, value_addr(*arg1p)); + class = value_field(value_ind(g_arg1p), 0); + class = value_cast_pointers (classtype, class); + + method = value_struct_elt (&class, args, name, static_memfuncp, NULL); +#endif + + return method; +} + +struct value * +vala_search_priv_field (char *name, struct value *arg1, int offset, struct type *type) +{ + struct value *priv; + struct type *privtype; + int i; + + if (!VALA_TYPE_HAS_PRIV (type)) + return NULL; + + priv = value_ind (value_field (arg1, 1)); + privtype = check_typedef (value_type(priv)); + for (i = 0; i < TYPE_NFIELDS (privtype); i++) + { + char *field_name = TYPE_FIELD_NAME (privtype, i); + if (streq (name, field_name)) + return value_field (priv, i); + } + + return NULL; +} + + +extern int +vala_check_priv_field (struct value *arg1, const char *name) +{ + struct value *v = arg1; + struct type *t = value_type (v); + + while (TYPE_CODE(CHECK_TYPEDEF(t)) == TYPE_CODE_PTR) + { + t = TYPE_TARGET_TYPE(t); + v = value_ind(v); + } + if (VALA_TYPE_HAS_PRIV(t)) + return check_field (value_field(v, 1), name); + else + return 0; +} diff -uprN -x '*~' gdb-6.8/gdb/vala-lang.h gdb-6.8-vala/gdb/vala-lang.h --- gdb-6.8/gdb/vala-lang.h 1970-01-01 00:00:00.000000000 +0000 +++ gdb-6.8-vala/gdb/vala-lang.h 2008-08-18 13:34:41.000000000 +0100 @@ -0,0 +1,42 @@ + + +//extern struct field* vala_type_get_fields (struct type* type, int* nfields); +//extern struct field* vala_type_get_private_fields (struct type* type, int* nfields); + +extern char *vala_member_name (const char*, const char*); +//extern char* vala_demangle (const char *, int); +extern struct value *vala_search_method (char *, struct value **, struct value **, + int, int *, struct type *); +extern struct value *vala_search_priv_field (char *, struct value *, int, struct type *); + +extern int vala_check_priv_field (struct value *, const char *); +extern struct field* vala_type_get_private_fields (struct type*, int*); +//extern struct value* vala_value_field (struct value *arg1, int fieldno, int private); + +//struct type* vala_lookup_transparent_type (const char* name); + +extern void vala_print_type (struct type *, char *, struct ui_file *, int, int); +extern int vala_val_print (struct type *, const gdb_byte *, int, CORE_ADDR, + struct ui_file *, int, int, int, enum val_prettyprint); +extern int vala_value_print (struct value *, struct ui_file *, int, + enum val_prettyprint); +/*vala_print_type +vala_val_print +vala_value_print*/ + +/*vala_skip_trampoline +vala_value_of_this +vala_lookup_transparent_type +vala_demangle*/ + + +#define VALA_TYPE_NAME(type) ((TYPE_TAG_NAME (type) != NULL && \ + TYPE_TAG_NAME (type)[0] == '_') ? \ + TYPE_TAG_NAME (type) + 1 : TYPE_TAG_NAME (type)) + +#define VALA_TYPE_IS_CLASS(type) (TYPE_FIELDS (type) != NULL && \ + (streq (TYPE_FIELD_NAME(type, 0), "parent_instance") \ + || streq (TYPE_FIELD_NAME(type, 0), "g_type_instance"))) +#define VALA_TYPE_BASE_CLASS(class) (check_typedef(TYPE_FIELD_TYPE (class, 0))) +#define VALA_TYPE_HAS_PRIV(type) (TYPE_NFIELDS (type) >= 2 && \ + streq (TYPE_FIELD(type,1).name, "priv")) diff -uprN -x '*~' gdb-6.8/gdb/vala-print.c gdb-6.8-vala/gdb/vala-print.c --- gdb-6.8/gdb/vala-print.c 1970-01-01 00:00:00.000000000 +0000 +++ gdb-6.8-vala/gdb/vala-print.c 2008-08-18 17:14:54.000000000 +0100 @@ -0,0 +1,334 @@ +#include "defs.h" +#include "symtab.h" +#include "gdbtypes.h" +#include "expression.h" +#include "parser-defs.h" +#include "language.h" +#include "gdb_string.h" +#include "value.h" +#include "target.h" +#include "infcall.h" +#include "vala-lang.h" +#include "c-lang.h" +#include "jv-lang.h" +#include + +//static struct field* vala_type_get_private_fields (struct type *, int *); +static struct field* vala_type_get_fields (struct type *, int *); + + +extern void +vala_print_type (struct type *type, char *varstring, struct ui_file *stream, + int show, int level) +{ + struct type *real_type; + char *name; + int offset; + + switch (TYPE_CODE (type)) + { + case TYPE_CODE_PTR: + real_type = check_typedef (TYPE_TARGET_TYPE (type)); + if (TYPE_CODE (real_type) == TYPE_CODE_STRUCT) + { + /* it's either a class or a ptr to a struct */ + if (VALA_TYPE_IS_CLASS (real_type)) + { + struct field *fields, *privfields; + int nfields, nprivfields; + + /* it's a GType based class */ + if (show > 0) + fputs_filtered ("class ", stream); + + fputs_filtered (VALA_TYPE_NAME(real_type), stream); + + if (show > 0) + { + name = VALA_TYPE_NAME (VALA_TYPE_BASE_CLASS (real_type)); + if (strcmp (name, "GTypeInstance") != 0) + { + fputs_filtered (" : ", stream); + fputs_filtered (name, stream); + } + fields = vala_type_get_fields (real_type, &nfields); + privfields = vala_type_get_private_fields (real_type, &nprivfields); + if (nfields + nprivfields > 0) + { + int i,j; + + fputs_filtered (" {\n", stream); + + for (i = 0; i < nfields; i++) + { + struct field f = fields[i]; + for (j=0;j 0) + { + fputs_filtered (TYPE_CODE(type) == TYPE_CODE_STRUCT ? + "struct " : "enum ", stream); + } + fputs_filtered (VALA_TYPE_NAME(type), stream); + if (show > 0 && TYPE_NFIELDS (type) > 0) + { + int i; + fputs_filtered (" {\n", stream); + for (i = 0; i < TYPE_NFIELDS (type); i++) + { + struct field f = TYPE_FIELD (type, i); + vala_print_type (f.type, f.name, stream, 0, level); + } + fputs_filtered ("}", stream); + } + break; + case TYPE_CODE_VOID: + fputs_filtered ("void", stream); + break; + case TYPE_CODE_TYPEDEF: + if (streq (TYPE_NAME(type), "gboolean")) + { + fputs_filtered ("bool", stream); + } + else if (TYPE_NAME(type)[0] == 'g') + { + /* this should cover most glib types */ + fputs_filtered (TYPE_NAME(type)+1, stream); + fputs_filtered (varstring, stream); + } + else + { + vala_print_type(TYPE_TARGET_TYPE (type), + varstring, stream, show, level); + } + break; + case TYPE_CODE_FUNC: + vala_print_type (TYPE_TARGET_TYPE(type), "", stream, show, level); + fputs_filtered (" (", stream); + for (offset = 0; offset < TYPE_NFIELDS(type); ++offset) + { + vala_print_type (TYPE_FIELDS(type)[offset].type, + TYPE_FIELDS(type)[offset].name, + stream, show-1, 0); + } + fputs_filtered (");", stream); + break; + default : + /* use c_print_type as a fallback */ + c_print_type (type, varstring, stream, show, level); + } + if (varstring != NULL && *varstring != '\0') + { + fputs_filtered (" ", stream); + fputs_filtered (varstring, stream); + fputs_filtered (";\n", stream); + } +} + +extern int +vala_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, + CORE_ADDR address, struct ui_file *stream, int format, + int deref_ref, int recurse, enum val_prettyprint pretty) +{ + CORE_ADDR addr; + int i, nfields; + struct field* fields; + + if (TYPE_NAME(type) && streq (TYPE_NAME(type), "gboolean")) + { + if (format) + print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream); + else + { + long val = unpack_long (type, valaddr + embedded_offset); + if (val == 0) + fputs_filtered ("false", stream); + else + fputs_filtered ("true", stream); + } + return 0; + } + + CHECK_TYPEDEF(type); + switch (TYPE_CODE(type)) + { + case TYPE_CODE_PTR: + if (format && format != 's') + { + print_scalar_formatted (valaddr, type, format, 0, stream); + return 0; + } + addr = unpack_pointer (type, valaddr); + if (addr == 0) + { + fputs_filtered ("null", stream); + return 0; + } + break; + case TYPE_CODE_STRUCT: + fputs_filtered ("{ ", stream); + if (VALA_TYPE_IS_CLASS (type) && + strcmp (TYPE_FIELD_NAME (type,0), "g_type_instance") != 0) + { + fputs_filtered ("base = ", stream); + val_print (VALA_TYPE_BASE_CLASS (type), valaddr, embedded_offset, + address, stream, format, deref_ref, recurse, pretty); + fputs_filtered ("; ", stream); + } + + fields = vala_type_get_fields (type, &nfields); + for (i = 0; i < nfields; i++) + { + fprintf_filtered (stream, "%s = ", fields[i].name); + val_print (fields[i].type, valaddr + FIELD_BITPOS (fields[i]) / 8, + 0, address + FIELD_BITPOS (fields[i]) / 8, stream, + format, deref_ref, recurse + 1, pretty); + fputs_filtered ("; ", stream); + } + if (VALA_TYPE_HAS_PRIV (type)) + { + struct type *privtype; + struct value *self, *priv; + + privtype = check_typedef (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 1))); + self = value_from_pointer (lookup_pointer_type (type), address); + priv = value_ind (value_field (value_ind(self), 1)); + + fields = vala_type_get_private_fields (type, &nfields); + for (i = 0; i < nfields; i++) + { + + fprintf_filtered (stream, "%s = ", fields[i].name); + common_val_print (value_field (priv, i), stream, + format, deref_ref, recurse + 1, pretty); + fputs_filtered ("; ", stream); + } + } + /*if (pretty) + { + fputs_filtered ("\n", stream); + print_spaces_filtered (2 + 2 * recurse, stream); + + FIXME : + }*/ + + fputs_filtered ("}", stream); + return 0; + /* default: + */ + } + return c_val_print(type, valaddr, embedded_offset, address, stream, format, + deref_ref, recurse, pretty); +} + +extern int +vala_value_print (struct value *val, struct ui_file *stream, int format, + enum val_prettyprint pretty) +{ + struct type *type = check_typedef(value_type(val)); + if (TYPE_CODE(type) == TYPE_CODE_PTR && + TYPE_CODE(check_typedef(TYPE_TARGET_TYPE(type))) == TYPE_CODE_STRUCT) + { + return c_value_print (value_ind (val), stream, format, pretty); + } + return c_value_print (val, stream, format, pretty); +} + + + +/* Helpers for vala_print_type */ +static struct field* +vala_type_get_fields (struct type* type, int* nfields) +{ + int offset = 0; + + if (TYPE_CODE(type) != TYPE_CODE_STRUCT) + /* error */ + return NULL; + + if (TYPE_FIELDS (type) != NULL && VALA_TYPE_IS_CLASS(type)) + { + offset = 1; + if (VALA_TYPE_HAS_PRIV(type)) + { + offset = 2; + } + } + if (nfields != NULL) + *nfields = TYPE_NFIELDS (type) - offset; + return TYPE_FIELDS (type) + offset; +} + +struct field* +vala_type_get_private_fields (struct type* type, int* nfields) +{ + struct type* priv; + + if (TYPE_CODE(type) != TYPE_CODE_STRUCT) + /* error */ + return NULL; + + if (nfields != NULL) + *nfields = 0; + + if (VALA_TYPE_IS_CLASS(type) && VALA_TYPE_HAS_PRIV(type)) + { + priv = check_typedef (TYPE_TARGET_TYPE (TYPE_FIELD(type,1).type)); + + if (nfields != NULL) + *nfields = TYPE_NFIELDS(priv); + + return TYPE_FIELDS(priv); + } + + return NULL; +} diff -uprN -x '*~' gdb-6.8/gdb/valops.c gdb-6.8-vala/gdb/valops.c --- gdb-6.8/gdb/valops.c 2008-02-04 01:23:04.000000000 +0100 +++ gdb-6.8-vala/gdb/valops.c 2008-08-17 17:09:33.000000000 +0100 @@ -36,6 +36,7 @@ #include "infcall.h" #include "dictionary.h" #include "cp-support.h" +#include "vala-lang.h" #include "dfp.h" #include @@ -1255,6 +1256,7 @@ search_struct_field (char *name, struct CHECK_TYPEDEF (type); if (!looking_for_baseclass) + { for (i = TYPE_NFIELDS (type) - 1; i >= nbases; i--) { char *t_field_name = TYPE_FIELD_NAME (type, i); @@ -1322,6 +1324,14 @@ search_struct_field (char *name, struct } } + if (current_language->la_language == language_vala) + { + struct value *v = vala_search_priv_field (name, arg1, offset, type); + if (v) + return v; + } + } + for (i = 0; i < nbases; i++) { struct value *v; @@ -1468,6 +1478,13 @@ search_struct_method (char *name, struct } } + if (current_language->la_language == language_vala) + { + v = vala_search_method (name, arg1p, args, offset, static_memfuncp, type); + if (v != NULL) + return v; + } + for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) { int base_offset;