diff --exclude=CVS -urN current/gdb/c-lang.c current-demangle_d/gdb/c-lang.c --- current/gdb/c-lang.c 2005-12-17 23:33:59.000000000 +0100 +++ current-demangle_d/gdb/c-lang.c 2006-04-22 18:22:35.000000000 +0200 @@ -27,6 +27,7 @@ #include "parser-defs.h" #include "language.h" #include "c-lang.h" +#include "d-lang.h" #include "valprint.h" #include "macroscope.h" #include "gdb_assert.h" @@ -735,10 +736,48 @@ LANG_MAGIC }; +const struct language_defn d_language_defn = +{ + "d", /* Language name */ + language_d, + NULL, + range_check_off, + type_check_off, + case_sensitive_on, + array_row_major, + &exp_descriptor_standard, + c_preprocess_and_parse, + c_error, + null_post_parser, + c_printchar, /* Print a character constant */ + c_printstr, /* Function to print string constant */ + c_emit_char, /* Print a single char */ + c_create_fundamental_type, /* Create fundamental type in this language */ + c_print_type, /* Print a type using appropriate syntax */ + c_val_print, /* Print a value using appropriate syntax */ + c_value_print, /* Print a top-level value */ + NULL, /* Language specific skip_trampoline */ + NULL, /* value_of_this */ + basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ + basic_lookup_transparent_type,/* lookup_transparent_type */ + d_demangle, /* Language specific symbol demangler */ + NULL, /* Language specific class_name_from_physname */ + c_op_print_tab, /* expression operators for printing */ + 1, /* c-style arrays */ + 0, /* String lower bound */ + NULL, + default_word_break_characters, + c_language_arch_info, + default_print_array_index, + LANG_MAGIC +}; + + void _initialize_c_language (void) { add_language (&c_language_defn); + add_language (&d_language_defn); add_language (&cplus_language_defn); add_language (&asm_language_defn); add_language (&minimal_language_defn); diff --exclude=CVS -urN current/gdb/defs.h current-demangle_d/gdb/defs.h --- current/gdb/defs.h 2006-02-25 05:36:39.000000000 +0100 +++ current-demangle_d/gdb/defs.h 2006-04-22 18:22:35.000000000 +0200 @@ -202,6 +202,7 @@ language_auto, /* Placeholder for automatic setting */ language_c, /* C */ language_cplus, /* C++ */ + language_d, /* D */ language_objc, /* Objective-C */ language_java, /* Java */ language_fortran, /* Fortran */ diff --exclude=CVS -urN current/gdb/demangle_d/config.h current-demangle_d/gdb/demangle_d/config.h --- current/gdb/demangle_d/config.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/config.h 2006-04-23 01:01:44.000000000 +0200 @@ -0,0 +1,119 @@ +#ifndef DEMANGLE_D_CONFIG_H +#define DEMANGLE_D_CONFIG_H 1 + +#include "demangle.h" + +#undef DEMANGLE_D_REQUIRE_ISDIGIT +#undef DEMANGLE_D_REQUIRE_ISXDIGIT +#undef DEMANGLE_D_REQUIRE_ASCI2HEX + +#ifdef DEMANGLE_D_IN_VALGRIND + +/* valgrind - http://www.valgrind.org */ + +#include /* size_t */ + +#define xstrlen VG_(strlen) +#define xstrncmp VG_(strncmp) +#define xsnprintf VG_(snprintf) +#define xisdigit ISDIGIT +#define DEMANGLE_D_REQUIRE_ISDIGIT 1 +#define xisxdigit ISXDIGIT +#define DEMANGLE_D_REQUIRE_ISXDIGIT 1 +#define xasci2hex ASCI2HEX +#define DEMANGLE_D_REQUIRE_ASCI2HEX 1 + + +#elif defined(DEMANGLE_D_IN_GDB) /* not DEMANGLE_D_IN_VALGRIND */ + +/* gdb - http://www.gnu.org/software/gdb/ */ + +#include /* size_t */ + +#include +#define xstrlen strlen +#define xstrncmp strncmp + + +#include "../defs.h" +/* xsnprintf */ + +#include "../../include/safe-ctype.h" +#define xisdigit ISDIGIT +#define xisxdigit ISXDIGIT + +#define xasci2hex ASCI2HEX +#define DEMANGLE_D_REQUIRE_ASCI2HEX 1 + + +#else /* not DEMANGLE_D_IN_GDB */ + +/* "normal" libc */ + +#include /* size_t */ + +#include +#define xstrlen strlen +#define xstrncmp strncmp + +#include +#define xabort abort + +#include +#define xsnprintf snprintf + +#include +#define xisdigit isdigit +#define xisxdigit isxdigit + +#define xasci2hex ASCI2HEX +#define DEMANGLE_D_REQUIRE_ASCI2HEX 1 + + +#endif /* not DEMANGLE_D_IN_VALGRIND && not DEMANGLE_D_IN_GDB */ + +#include +#ifdef _LIBINTL_H +#define _(str) gettext(str) +#else +#define _(str) str +#endif + +/* helper macros */ + +#ifdef DEMANGLE_D_REQUIRE_ISDIGIT +#define ISDIGIT(c) (('0' <= (c)) && ((c) <= '9')) +#endif + +#ifdef DEMANGLE_D_REQUIRE_ISXDIGIT +#define ISXDIGIT(c) ( \ + (('0' <= (c)) && ((c) <= '9')) \ + || (('a' <= (c)) && ((c) <= 'f')) \ + || (('A' <= (c)) && ((c) <= 'F')) \ + ) +#endif + +#ifdef DEMANGLE_D_REQUIRE_ASCI2HEX +#define ASCI2HEX(c) \ + ( \ + ('a' <= (c) && (c) <= 'f') \ + ? \ + ((c) - 'a' + 10) \ + : \ + ( \ + ('A' <= (c) && (c) <= 'F') \ + ? \ + ((c) - 'A' + 10) \ + : \ + ( \ + ('0' <= (c) && (c) <= '9') \ + ? \ + ((c) - '0') \ + : \ + 0 \ + ) \ + ) \ + ) +#endif + +#endif /* DEMANGLE_D_CONFIG_H */ diff --exclude=CVS -urN current/gdb/demangle_d/COPYING current-demangle_d/gdb/demangle_d/COPYING --- current/gdb/demangle_d/COPYING 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/COPYING 2006-04-23 00:37:13.000000000 +0200 @@ -0,0 +1,352 @@ +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent modules, +and to copy and distribute the resulting executable under terms of your choice, +provided that you also meet, for each linked independent module, the terms and +conditions of the license of that module. An independent module is a module +which is not derived from or based on this library. If you modify this library, +you may extend this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this exception +statement from your version. + + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --exclude=CVS -urN current/gdb/demangle_d/demangle.c current-demangle_d/gdb/demangle_d/demangle.c --- current/gdb/demangle_d/demangle.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/demangle.c 2006-04-23 00:34:16.000000000 +0200 @@ -0,0 +1,5 @@ +/* used as source drop for plugins without the need to adapt the build system */ +#include "main.c" +#include "parser.c" +#include "string.c" +#include "util.c" diff --exclude=CVS -urN current/gdb/demangle_d/demangle.h current-demangle_d/gdb/demangle_d/demangle.h --- current/gdb/demangle_d/demangle.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/demangle.h 2006-04-22 23:41:47.000000000 +0200 @@ -0,0 +1,21 @@ +#ifndef DEMANGLE_D_DEMANGLE_H +#define DEMANGEL_D_DEMANGLE_H 1 + +#define DD_(str) demangle_d_##str + +/* demangle a D symbol + * + * input: + * a NULL terminated mangled symbol + * + * output: + * UTF-8 encoded demangled symbol + * or NULL if unable to demangle + * + * memory: + * the caller is responsible to + * free input and output + */ +char* DD_(demangle_d)(char*); + +#endif /* DEMANGEL_D_DEMANGLE_H */ diff --exclude=CVS -urN current/gdb/demangle_d/main.c current-demangle_d/gdb/demangle_d/main.c --- current/gdb/demangle_d/main.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/main.c 2006-04-23 01:02:46.000000000 +0200 @@ -0,0 +1,59 @@ +/* + * demangle_d - pluggable D de-mangler + * Copyright (C) 2006 Thomas Kuehne + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent modules, + * and to copy and distribute the resulting executable under terms of your + * choice, provided that you also meet, for each linked independent module, + * the terms and conditions of the license of that module. An independent + * module is a module which is not derived from or based on this library. If + * you modify this library, you may extend this exception to your version of + * the library, but you are not obligated to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifdef DEMANGLE_D_STANDALONE +#include "parser.h" +#include "util.h" + +int +main(int argc, char** argv) +{ + int i; + if (argc < 2) + { + xfprintf(stderr, + _("pluggable D d-demangler by Thomas Kuehne (%s)\n"), + "$Date: 2006-04-22T18:03:19.787625Z $"); + xfprintf(stderr, _("%s [ ...]\n"), + argc ? argv[0] :"demangle_d"); + return (EXIT_FAILURE); + } + for (i = 1; i < argc; i++) + { + char* demangled = DD_(demangle_d)(argv[i]); + if (1 > xprintf(_("%s\t%s\n"), argv[i], demangled)) + xperror(NULL); + if (demangled) + xfree(demangled); + } + return (EXIT_SUCCESS); +} +#endif /* DEMANGLE_D_STANDALONE */ diff --exclude=CVS -urN current/gdb/demangle_d/parser.c current-demangle_d/gdb/demangle_d/parser.c --- current/gdb/demangle_d/parser.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/parser.c 2006-04-23 01:13:26.000000000 +0200 @@ -0,0 +1,694 @@ +/* + * demangle_d - pluggable D de-mangler + * Copyright (C) 2006 Thomas Kuehne + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent modules, + * and to copy and distribute the resulting executable under terms of your + * choice, provided that you also meet, for each linked independent module, + * the terms and conditions of the license of that module. An independent + * module is a module which is not derived from or based on this library. If + * you modify this library, you may extend this exception to your version of + * the library, but you are not obligated to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "parser.h" +#include "util.h" + +/* Parse until the end of the next type and return the pointer to the first + uninterpreted charachter or NULL. Set is_nested if a nested type + (e.g. index of AA or template/function parameter) is parsed. */ +char* +next_type(dest, source, is_nested) + string_t dest; char* source; int is_nested; +{ + if (!source || !source[0]) + return NULL; + + if ((source[0] == '_') && (source[1] == 'D') && xisdigit(source[2]) + && (source[2] != '0')) + { + string_t tmp; + tmp = new_string(); + source = next_type(tmp, source + 2, 0); + if (dest->used && (dest->str[dest->used] != '.')) + append_c(dest, '.'); + append_n(dest, tmp->str, tmp->used); + xfree(tmp->str); + xfree(tmp); + return source; + } + + switch(source[0]) + { + case 'v': + nestpend(dest, "void", is_nested); + source += 1; + break; + case 'b': /* deprecated since DMD-0.148 (2006-02-25) */ + nestpend(dest, "bit", is_nested); + source += 1; + break; + case 'x': + nestpend(dest, "bool", is_nested); + source += 1; + break; + case 'g': + nestpend(dest, "byte", is_nested); + source += 1; + break; + case 'h': + nestpend(dest, "ubyte", is_nested); + source += 1; + break; + case 's': + nestpend(dest, "short", is_nested); + source += 1; + break; + case 't': + nestpend(dest, "ushort", is_nested); + source += 1; + break; + case 'i': + nestpend(dest, "int", is_nested); + source += 1; + break; + case 'k': + nestpend(dest, "uint", is_nested); + source += 1; + break; + case 'l': + nestpend(dest, "long", is_nested); + source += 1; + break; + case 'm': + nestpend(dest, "ulong", is_nested); + source += 1; + break; + case 'f': + nestpend(dest, "float", is_nested); + source += 1; + break; + case 'd': + nestpend(dest, "double", is_nested); + source += 1; + break; + case 'e': + nestpend(dest, "real", is_nested); + source += 1; + break; + case 'o': + nestpend(dest, "ifloat", is_nested); + source += 1; + break; + case 'p': + nestpend(dest, "idouble", is_nested); + source += 1; + break; + case 'j': + nestpend(dest, "ireal", is_nested); + source += 1; + break; + case 'q': + nestpend(dest, "cfloat", is_nested); + source += 1; + break; + case 'r': + nestpend(dest, "cdouble", is_nested); + source += 1; + break; + case 'c': + nestpend(dest, "creal", is_nested); + source += 1; + break; + case 'a': + nestpend(dest, "char", is_nested); + source += 1; + break; + case 'u': + nestpend(dest, "wchar", is_nested); + source += 1; + break; + case 'w': + nestpend(dest, "dchar", is_nested); + source += 1; + break; + + case 'A': /* dynamic array */ + if (!is_nested) + prepend(dest, "[] "); + source = next_type(dest, source+1, is_nested); + if (is_nested) + append(dest, "[]"); + break; + + case 'G': /* static array */ + { + char* start; + char* end; + start = ++source; + end = start; + + while (xisdigit(*end)) + end++; + + if (!is_nested) + { + prepend(dest, "] "); + prepend_n(dest, start, end-start); + prepend(dest, "["); + } + source = next_type(dest, end, is_nested); + if (is_nested) + { + append_c(dest, '['); + append_n(dest, start, end-start); + append_c(dest, ']'); + } + break; + } + + case 'H': /* associative array */ + { + string_t aa; + aa = new_string(); + source = next_type(aa, source+1, 1); + prepend(aa, "["); + append_c(aa, ']'); + source = next_type(aa, source, 0); + nestpend(dest, aa->str, is_nested); + xfree(aa->str); + xfree(aa); + break; + } + + case 'D': /* delegate */ + { + string_t sig; + sig = new_string(); + source = parse_function(sig, source+1, NULL, 0); + nestpend_n(dest, sig->str, sig->used, is_nested); + xfree(sig->str); + xfree(sig); + break; + } + + case 'P': /* pointer */ + if ((source[1] == 'F') || (source[1]=='U') || (source[1]=='W') + || (source[1]=='V') || (source[1]=='R')) + { + /* function */ + string_t sig; + sig = new_string(); + source = parse_function(sig, source+1, "", 0); + nestpend_n(dest, sig->str, sig->used, is_nested); + xfree(sig->str); + xfree(sig); + } + else + { + /* 'normal' type */ + if (!is_nested) + prepend(dest, "* "); + source = next_type(dest, source+1, is_nested); + if (is_nested) + append(dest, " *"); + } + break; + + case 'J': /* out */ + append(dest, "out "); + source = next_type(dest, source+1, 1); + break; + + case 'K': /* inout */ + append(dest, "inout "); + source = next_type(dest, source+1, 1); + break; + + case 'C': /* class */ + case 'S': /* struct */ + case 'E': /* enum */ + case 'T': /* typedef */ + { +#ifdef DEMANGLE_D_VERBOSE + char tmp; + tmp = source[0]; +#endif /* DEMANGLE_D_VERBOSE */ + if (!is_nested) + { + string_t sig; + sig = new_string(); + source = next_type(sig, source+1, 0); + append_c(sig, ' '); +#ifdef DEMANGLE_D_VERBOSE + switch (tmp) + { + case 'C': + prepend(sig, "class "); + break; + case 'S': + prepend(sig, "struct "); + break; + case 'E': + prepend(sig, "enum "); + break; + case 'T': + prepend(sig, "typedef "); + break; + } +#endif /* DEMANGLE_D_VERBOSE */ + prepend_n(dest, sig->str, sig->used); + xfree(sig->str); + xfree(sig); + } + else + { +#ifdef DEMANGLE_D_VERBOSE + switch (tmp) + { + case 'C': + append(dest, "class "); + break; + case 'S': + append(dest, "struct "); + break; + case 'E': + append(dest, "enum "); + break; + case 'T': + append(dest, "typedef "); + break; + } +#endif /* DEMANGLE_D_VERBOSE */ + source = next_type(dest, source+1, 1); + } + break; + } + + case '1': /* qualified name */ + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + int first_round; + first_round = 1; + + while (source && xisdigit(source[0]) && (source[0] != '0')) + { + long int len; + len = xstrtol_10(source, &source); + + if (!first_round) + append_c(dest, '.'); + else + first_round = 0; + + if (len >= 5 && (source[0] == '_') && (source[1] == '_') + && (source[2] == 'T') && xisdigit(source[3]) + && (source[3] != '0')) + { + /* template */ + char* template; + template = xstrndup(source + 3, len-3); + interprete_template(dest, template); + xfree(template); + } + else if((len == 5) && (xstrncmp(source, "_ctor", len) == 0)) + append(dest, "this"); + else if((len == 5) && (xstrncmp(source, "_dtor", len) == 0)) + append(dest, "~this"); + else if((len == 11) + && (xstrncmp(source, "_staticCtorFZv", len + 3) == 0)) + { + prepend(dest, "static void "); + append(dest, "this()"); + source = source + 11 + 3; + break; + } + else if((len == 11) + && (xstrncmp(source, "_staticDtorFZv", len + 3) == 0)) + { + prepend(dest, "static void "); + append(dest, "~this()"); + source = source + 11 + 3; + break; + } + else + /* plain identifier part */ + append_n(dest, source, len); + + source += len; + } + if (!is_nested) + source = next_type(dest, source, 0); + break; + } + + case 'F': /* D function */ + case 'U': /* C function */ + case 'W': /* Windows function */ + case 'V': /* Pascal function */ + case 'R': /* C++ function */ + if (!is_nested) + { + string_t id; + id = new_string(); + append_n(id, dest->str, dest->used); + dest->used = 0; + dest->str[0] = '\x00'; + source = parse_function(dest, source, id->str, 0); + xfree(id->str); + xfree(id); + } + else + source = parse_function(dest, source, "", 1); + break; + + default: + append(dest, " @bug@[2]{"); + append(dest, source); + append_c(dest, '}'); + source = NULL; + break; + } + + return source; +} + +/* Parse a "real" template parameter and return a pointer to the first not + interpreted character. */ +char* +parse_real(dest, source) + string_t dest; char* source; +{ + /* FIXME architecture dependent */ + long double f; + size_t i; + int tmp; + char* buffer; + unsigned char* c; + + c = (unsigned char*) &f; + + for (i = 0; i < 10; i++) + { + if (!xisxdigit(source[i * 2]) || !xisxdigit(source[i * 2 + 1])) + { +format_error: + append(dest, "0x"); + append_n(dest, source, 20); + return source + 20; + } + c[i] = (xasci2hex(source[i * 2]) << 4); + c[i] |= xasci2hex(source[i * 2 + 1]); + } + + buffer = xmalloc(64); + tmp = xsnprintf(buffer, 64, "%Lf", f); + if (tmp < 1) + { + xfree(buffer); + goto format_error; + } + append_n(dest, buffer, tmp); + xfree(buffer); + return source + 20; +} + +/* Parse a function - including arguments and return type - and + return a pointer to the first not interpreted character. */ +char* +parse_function(dest, source, name, is_nested) + string_t dest; char* source; char* name; int is_nested; +{ + string_t fn_return; + string_t fn_param; + + fn_return = new_string(); + fn_param = new_string(); + + source++; + + /* params */ + if (source[0] != 'Z') + { + if (source[0] == 'Y') + { + append(fn_param, "..."); + goto var_arg_param; + } + source = next_type(fn_param, source, 1); + while (source && source[0] && source[0]!='Z') + { + if (source[0] == 'Y') + { + append(fn_param, ", ..."); + goto var_arg_param; + } + else if(source[0] == 'X') + { + append(fn_param, " ..."); + goto var_arg_param; + } + append(fn_param, ", "); + source = next_type(fn_param, source, 1); + } + } + + /* return type */ + if (source && source[0] == 'Z') +var_arg_param: + source = next_type(fn_return, source + 1, 1); + + /* output */ + if (name && name[0]) + if (! is_nested) + { + prepend(dest, " "); + prepend_n(dest, fn_return->str, fn_return->used); + append(dest, name); + } + else + { + append_n(dest, fn_return->str, fn_return->used); + append_c(dest, ' '); + append(dest, name); + } + else if(name) + { + append_n(dest, fn_return->str, fn_return->used); + append(dest, " function"); + } + else + { + append_n(dest, fn_return->str, fn_return->used); + append(dest, " delegate"); + } + + if (fn_param->used) + { + append_c(dest, '('); + append_n(dest, fn_param->str, fn_param->used); + append_c(dest, ')'); + } + else + append(dest, "()"); + + xfree(fn_return->str); + xfree(fn_return); + xfree(fn_param->str); + xfree(fn_param); + + return source; +} + +/* Interprete the NULL terminated template symbol. */ +void +interprete_template(dest, raw) + string_t dest; char* raw; +{ + char* tmp; + long int dataLen; + int first_arg; + + first_arg = 1; + + /* id */ + while (xisdigit(raw[0]) && (raw[0] != '0')) + { + long int len; + len = xstrtol_10(raw, &raw); + append_n(dest, raw, len); + raw += len; + } + append(dest, "!("); + + /* arguments */ + while (raw && raw[0]) + { + if (raw[0] == 'T') + { + /* type parameter */ + raw++; + if (!first_arg) + append(dest, ", "); + else + first_arg = 0; + raw = next_type(dest, raw, 1); + } + else if(raw[0] == 'V') + { + /* value parameter */ + if (!first_arg) + append(dest, ", "); + else + first_arg = 0; + raw = next_type(dest, raw + 1, 1); + append_c(dest, ' '); + if (xisdigit(raw[0])) + { + /* positive integer */ +integer_arg: + tmp = raw; + while (xisdigit(raw[0])) + raw++; + append_n(dest, tmp, raw-tmp); + } + else if(raw[0] == 'N') + { + /* negative integer */ + raw++; + append_c(dest, '-'); + goto integer_arg; + } + else if(raw[0] == 'e') + /* float */ + raw = parse_real(dest, raw+1); + else if(raw[0] == 'c') + { + /* complex float */ + raw = parse_real(dest, raw+1); + append(dest, " + "); + raw = parse_real(dest, raw); + append_c(dest, 'i'); + } + else if(raw[0] == 'n') + { + append(dest, "null"); + raw++; + } + else if((raw[0] == 'a') || (raw[0] == 'w') || (raw[0] == 'd')) + { + /* character literal */ + raw++; + if (!xisdigit(raw[0])) + goto bug; + dataLen = xstrtol_10(raw, &raw); + if (raw[0] != '_') + goto bug; + raw++; + append_c(dest, '"'); + while (dataLen--) + { + if (xisxdigit(raw[0]) && xisxdigit(raw[1])) + append_c(dest, (xasci2hex(raw[0]) << 4) + + xasci2hex(raw[1])); + else + append_c(dest, '?'); + raw += 2; + } + append_c(dest, '"'); + } + else + goto bug; + } + else if(raw[0] == 'Z') + /* end of parameter list */ + break; + else + { +bug: + append(dest, " @bug@[1]{"); + append(dest, raw); + append_c(dest, '}'); + break; + } + } + append_c(dest, ')'); +} + +/* Demangle the NULL-terminated D symbol and return the UTF-8 encoded + representation or NULL. The caller is responsible to free input and + output. */ +char* +demangle_d(source) + char* source; +{ + string_t dest; + string_t nested; + char* back; + + if ((source[0] != '_') || (source[1] != 'D') || (!xisdigit(source[2])) + || (source[2] == '0')) + { + /* FIXME might be mangled with 'D' but hasn't 'D' linkage + * samples: + * _aaApply10treewalkerFPS3aaA3aaAZi + * _aaKeys9_aaKeys_xFPS3aaA3aaAZv + */ + /* FIXME handle special cases: + * _init__D1b11_staticCtorFZv3Al + * _Class__D1b11_staticCtorFZv3Ali + * _vtbl__D1b11_staticCtorFZv3Ali + * _modctor_1b + * _assert_1b + */ + return NULL; + } + else + source += 2; + + dest = new_string(); + + source = next_type(dest, source, 0); + + while (source && source[0]) + { + /* nested symbols */ + nested = new_string(); + append_c(dest, '.'); + source = next_type(nested, source, 0); + append_n(dest, nested->str, nested->used); + xfree(nested->str); + xfree(nested); + } + + back = xstrndup(dest->str, dest->used+1); + xfree(dest->str); + xfree(dest); + + return back; +} diff --exclude=CVS -urN current/gdb/demangle_d/parser.h current-demangle_d/gdb/demangle_d/parser.h --- current/gdb/demangle_d/parser.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/parser.h 2006-04-22 23:47:12.000000000 +0200 @@ -0,0 +1,21 @@ +#ifndef DEMANGLE_D_PARSER_H +#define DEMANGLE_D_PARSER_H 1 + +#include "config.h" +#include "string.h" + +#define next_type DD_(next_type) +#define interprete_template DD_(interprete_template) +#define parse_real DD_(parse_real) +#define parse_function DD_(parse_function) +#define demangle_d DD_(demangle_d) + +char* next_type(string_t dest, char* raw, int is_nested); + +void interprete_template(string_t dest, char* raw); + +char* parse_real(string_t dest, char* raw); + +char* parse_function(string_t dest, char* raw, char* name, int is_nested); + +#endif /* DEMANGLE_D_PARSER_H */ diff --exclude=CVS -urN current/gdb/demangle_d/README current-demangle_d/gdb/demangle_d/README --- current/gdb/demangle_d/README 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/README 2006-04-23 00:36:10.000000000 +0200 @@ -0,0 +1,65 @@ + pluggable D de-mangler +======================= + +Author: + Thomas Kuehne + +License: + GPL with linking exception (see license.txt) + + +Usage: stand alone +--------------------- + +1) compile: + cc -DDEMANGLE_D_STANDALONE -o demangle_d demangle.c + +2) run: + ./demangle_d _D3std3utf6toUTF8FG4awZAa _D3std6string7sformatFAaYAa + > _D3std3utf6toUTF8FG4awZAa char[] std.utf.toUTF8(char[4], dchar) + > _D3std6string7sformatFAaYAa char[] std.string.sformat(char[], ...) + + +Usage: plugin +--------------------- + +gdb: - ) +valgrind: - ) + +1) adapt config.h to your system + +2) include demangle.c in your build system + +3) demangle: + #include "demangle.h" + + char* mangled; + char* demangled; + + mangled = "_D1b5outerFeZf"; + demangled = DD_(demangle_d)(mangled); + + // ... process demangled ... + + if(demangled){ + free(demangled); + } + +optional: + adapt the DD_(str) macro in "demangle.h" to resolve potential + name clashes in your object code + + +TODO +--------------------- + + * better output for symbols in nested types: + _D1a11_staticCtorFZv1A11_staticCtorFZv5innerFHfeZHia + + * handle "special" names: + _init__D1b11_staticCtorFZv3Al + _Class__D1b11_staticCtorFZv3Ali + _vtbl__D1b11_staticCtorFZv3Ali + _modctor_1b + _assert_1b + diff --exclude=CVS -urN current/gdb/demangle_d/string.c current-demangle_d/gdb/demangle_d/string.c --- current/gdb/demangle_d/string.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/string.c 2006-04-23 01:14:44.000000000 +0200 @@ -0,0 +1,142 @@ +/* + demangle_d - pluggable D de-mangler + Copyright (C) 2006 Thomas Kuehne + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent modules, + and to copy and distribute the resulting executable under terms of your + choice, provided that you also meet, for each linked independent module, + the terms and conditions of the license of that module. An independent + module is a module which is not derived from or based on this library. If + you modify this library, you may extend this exception to your version of + the library, but you are not obligated to do so. If you do not wish to do + so, delete this exception statement from your version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* This file provieds functions for creating and modifing dynamic sized + strings. */ + +#include "config.h" +#include "string.h" +#include "util.h" + +/* Create and initialize a new string. */ +string_t +new_string(void) +{ + string_t str = xmalloc(sizeof(string_t)); + str->used = 0; + str->len = 128; + str->str = xmalloc(str->len); + str->str[0] = '\x00'; + return str; +} + +/* Append len bytes from source string to dest string. */ +void +append_n(dest, source, len) + string_t dest; const char* source; size_t len; +{ + size_t new_len; + new_len = dest->used + len + 1; + if (new_len > dest->len) + { + dest->len = new_len + (new_len >> 1); + dest->str = xrealloc(dest->str, dest->len); + } + xmemcpy(dest->str + dest->used, source, len); + dest->used += len; + dest->str[dest->used] = '\x00'; +} + +/* Append source char to dest string. */ +void +append_c(dest, source) + string_t dest; int source; +{ + size_t new_len; + new_len = dest->used + 2; + if (new_len > dest->len) + { + dest->len = new_len + (new_len >> 1); + dest->str = xrealloc(dest->str, dest->len); + } + dest->str[dest->used++] = (char)source; + dest->str[dest->used] = '\x00'; +} + +/* Append NULL-terminated string source to dest. */ +void +append(dest, source) + string_t dest; const char* source; +{ + append_n(dest, source, xstrlen(source)); +} + +/* Prepend len bytes from source string to dest string. */ +void +prepend_n(dest, source, len) + string_t dest; const char* source; size_t len; +{ + size_t new_len; + new_len = dest->used + len + 1; + if (new_len > dest->len) + { + dest->len = new_len + (new_len >> 1); + dest->str = xrealloc(dest->str, dest->len); + } + + if (dest->used) + xmemmove(dest->str + len, dest->str, dest->used); + + xmemcpy(dest->str, source, len); + dest->used += len; + dest->str[dest->used] = '\x00'; +} + +/* Prepend NULL-terminated string source to dest. */ +void +prepend(dest, source) + string_t dest; const char* source; +{ + prepend_n(dest, source, xstrlen(source)); +} + +/* If not nested, append len bytes from source string to dest else + prepend with space. */ +void +nestpend_n(dest, source, len, is_nested) + string_t dest; const char* source; size_t len; int is_nested; +{ + if (is_nested) + append_n(dest, source, len); + else + { + prepend(dest, " "); + prepend_n(dest, source, len); + } +} + +/* If not nested, append NULL-terminated source string to dest else + prepend with space. */ +void +nestpend(dest, source, is_nested) + string_t dest; const char* source; int is_nested; +{ + nestpend_n(dest, source, xstrlen(source), is_nested); +} + diff --exclude=CVS -urN current/gdb/demangle_d/string.h current-demangle_d/gdb/demangle_d/string.h --- current/gdb/demangle_d/string.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/string.h 2006-04-23 00:43:25.000000000 +0200 @@ -0,0 +1,67 @@ +#ifndef DEMANGLE_D_STRING_H +#define DEMANGLE_D_STRING_H 1 + +#include "config.h" + +#undef DEMANGLE_D_USE_LIBIBERY + +/*#ifdef DEMANGLE_D_IN_GDB + +#include "../../include/dyn-string.h" +#define DEMANGLE_D_USE_LIBIBERY 1 + +#elif defined(DEMANGLE_D_IN_VALGRIND) + +#include "../dyn-string.h" +#define DEMANGLE_D_USE_LIBIBERY 1 + +#endif*/ + +#ifdef DEMANGLE_D_USE_LIBIBERY + +#define string_t dyn_string_t +#define new_string() dyn_string(128) + +#define append_n DD_(append_n) +#define append_c dyn_string_append_char +#define append dyn_string_append_cstr + +#define prepend_n DD_(prepend_n) +#define prepend dyn_string_prepend_cstr + +#define nestpend_n DD_(nestpend_n) +#define nestpend DD_(nestpend) + +#else /* not DEMANGLE_D_USE_LIBIBERY */ + +#define string_t DD_(string_t) +#define new_string DD_(new_string) +#define append_n DD_(append_n) +#define append_c DD_(append_c) +#define append DD_(append) +#define prepend_n DD_(prepend_n) +#define prepend DD_(prepend) +#define nestpend_n DD_(nestpend_n) +#define nestpend DD_(nestpend) + +typedef struct{ + size_t used; + char* str; + size_t len; +}* string_t; + +string_t new_string(void); + +void append_c(string_t, int); +void append(string_t, const char *); +void prepend(string_t, const char *); + +#endif /* not DEMANGLE_D_USE_LIBIBERY */ + +void append_n(string_t, const char *, size_t); +void prepend_n(string_t, const char *, size_t); + +void nestpend_n(string_t, const char *, size_t, int); +void nestpend(string_t, const char*, int); + +#endif /* DEMANGLE_D_STRING_H */ diff --exclude=CVS -urN current/gdb/demangle_d/util.c current-demangle_d/gdb/demangle_d/util.c --- current/gdb/demangle_d/util.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/util.c 2006-04-23 00:08:43.000000000 +0200 @@ -0,0 +1,153 @@ +/* + demangle_d - pluggable D de-mangler + Copyright (C) 2006 Thomas Kuehne + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent modules, + and to copy and distribute the resulting executable under terms of your + choice, provided that you also meet, for each linked independent module, + the terms and conditions of the license of that module. An independent + module is a module which is not derived from or based on this library. If + you modify this library, you may extend this exception to your version of + the library, but you are not obligated to do so. If you do not wish to do + so, delete this exception statement from your version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* This file contains configuration dependent memory management helpers. */ + +#include "util.h" + +#ifdef DEMANGLE_D_REQUIRE_strndup +/* Copy n first bytes into a newly allocated buffer. */ +char* +DD_(strndup)(source, n) + const char* source; size_t n; +{ + char* dest; + dest = xmalloc(n+1); + xmemcpy(dest, source, n); + dest[n] = '\x00'; + return dest; +} +#endif + +#ifdef DEMANGLE_D_REQUIRE_memmove +/* Copy n bytes from memory area src to memory area dest. */ +void * DD_(memmove)(dest, src, n) + void *dest; const void *src; size_t n; +{ + void* tmp; + char* a; + const char* b; + + a = (char*) dest; + b = (const char*) src; + + if (((a < b) && (a + n < b)) || (((b < a) && (b + n < a)))) + return xmemcpy(dest, src, n); + else + { + tmp = xmalloc(n); + xmemcpy(tmp, src, n); + xmemcpy(dest, tmp, n); + xfree(tmp); + return dest; + } +} +#endif + + +#ifdef DEMANGLE_D_REQUIRE_strtol_10 +/* Convert the beginning of string src to an integer using base 10. + If endptr is not NULL, store the address of the first invalid character in + *endptr. */ +long int +DD_(strtol_10)(src, endptr) + char* src; char** endptr; +{ + long int value; + int sign; + + if (src[0] == '-') + { + sign = -1; + src++; + } + else if(src[0] == '+') + { + sign = 1; + src++; + } + else + sign = 1; + + value = 0; + + while (xisdigit(src[0])) + { + value = (value * 10) + (src[0] - '0'); + src++; + } + + if (endptr) + *endptr = src; + + return sign * value; +} +#endif + +#ifdef DEMANGLE_D_REQUIRE_malloc +/* Allocate n bytes and returns a pointer to the allocated memory. */ +void* +DD_(malloc)(n) + size_t n; +{ + void* ptr; + ptr = malloc(n); + if (!ptr) + DD_(error)(NULL); + return ptr; +} +#endif + +#ifdef DEMANGLE_D_REQUIRE_realloc +/* Changes the size of the memory block pointed to by ptr to len bytes. */ +void* +DD_(realloc)(ptr, len) + void* ptr; size_t len; +{ + ptr = realloc(ptr, len); + if (!ptr) + DD_(error)(NULL); + return ptr; +} +#endif + +#ifdef DEMANGLE_D_REQUIRE_error +/* Print error message and abort. If message is null, print the last + encountered system error and abort. */ +void +DD_(error)(message) + const char* message; +{ + if (message) + xfprintf(stderr, message); + else + xperror("demangle_d"); + xabort(); +} +#endif diff --exclude=CVS -urN current/gdb/demangle_d/util.h current-demangle_d/gdb/demangle_d/util.h --- current/gdb/demangle_d/util.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/util.h 2006-04-23 00:53:52.000000000 +0200 @@ -0,0 +1,99 @@ +#ifndef DEMANGLE_D_UTIL_H +#define DEMANGLE_D_UTIL_H 1 + +#include "config.h" + +#undef DEMANGLE_D_REQUIRE_strndup +#undef DEMANGLE_D_REQUIRE_strtol_10 +#undef DEMANGLE_D_REQUIRE_malloc +#undef DEMANGLE_D_REQUIRE_realloc +#undef DEMANGLE_D_REQUIRE_memmove +#undef DEMANGLE_D_REQUIRE_error + +#ifdef DEMANGLE_D_IN_VALGRIND +/* gdb - http://www.gnu.org/software/gdb/ */ + +#define xstrndup DD_(strndup) +#define DEMANGLE_D_REQUIRE_strndup 1 +#define xstrtol_10 DD_(strtol_10) +#define DEMANGLE_D_REQUIRE_strtol_10 1 +#define xmalloc VG_(malloc) +#define xrealloc VG_(realloc) +#define xmemmove DD_(memmove) +#define DEMANGLE_D_REQUIRE_memmove 1 +#define xfree VG_(free) +#define xmemcpy VG_(memcpy) + +#elif defined(DEMANGLE_D_IN_GDB) /* not DEMANGLE_D_IN_VALGRIND */ +/* gdb - http://www.gnu.org/software/gdb/ */ + +#include "../libiberty.h" +/* xmalloc */ +/* xrealloc */ + +#include "../defs.h" +/* xfree */ + +#include +#define xmemcpy memcpy +#define xmemmove memmove +#define xstrndup strndup +#define xstrtol_10(n,p) strtol((n), (p), 10) + +#else /* not DEMANGLE_D_IN_VALGRIND && not DEMANGLE_D_IN_GDB */ +/* 'normal' libc */ + +#include +#include + +#if defined(__USE_GNU) || defined(_GNU_SOURCE) +#define xstrndup strndup +#else +#define xstrndup DD_(strndup) +#define DEMANGLE_D_REQUIRE_strndup 1 +#endif + +#define xstrtol_10(n,p) strtol((n), (p), 10) + +#define xmalloc DD_(malloc) +#define DEMANGLE_D_REQUIRE_malloc 1 +#define xrealloc DD_(realloc) +#define DEMANGLE_D_REQUIRE_realloc 1 +#define xmemmove memmove +#define xfree free +#define xmemcpy memcpy + +#ifdef DEMANGLE_D_STANDALONE +#define DEMANGLE_D_REQUIRE_error 1 +#define xprintf printf +#define xperror perror +#define xfprintf fprintf +#endif + +#endif /* not DEMANGLE_D_IN_VALGRIND && not DEMANGLE_D_IN_GDB */ + +#ifdef DEMANGLE_D_REQUIRE_strndup +char* DD_(strndup)(const char*, size_t); +#endif + +#ifdef DEMANGLE_D_REQUIRE_strtol_10 +long int DD_(strtol_10)(char*, char**); +#endif + +#ifdef DEMANGLE_D_REQUIRE_malloc +void* DD_(malloc)(size_t); +#endif + +#ifdef DEMANGLE_D_REQUIRE_realloc +void* DD_(realloc)(void*, size_t); +#endif + +#ifdef DEMANGLE_D_REQUIRE_memmove +void * DD_(memmove)(void*, const void *, size_t ); +#endif + +#ifdef DEMANGLE_D_REQUIRE_error +void DD_(error)(const char*); +#endif + +#endif /* DEMANGLE_D_UTIL_H */ diff --exclude=CVS -urN current/gdb/demangle_d/version current-demangle_d/gdb/demangle_d/version --- current/gdb/demangle_d/version 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/version 2006-04-23 00:39:00.000000000 +0200 @@ -0,0 +1 @@ +$Date$ diff --exclude=CVS -urN current/gdb/d-lang.c current-demangle_d/gdb/d-lang.c --- current/gdb/d-lang.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/d-lang.c 2006-04-23 00:53:10.000000000 +0200 @@ -0,0 +1,34 @@ +/* C language support routines for GDB, the GNU debugger. + Copyright 2006 + Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include "defs.h" +#include "symtab.h" + +#define DEMANGLE_D_IN_GDB 1 +#include "demangle_d/demangle.c" + +char* d_demangle(char* symbol, int options) { + return DD_(demangle_d)(symbol); +} + +char* d_sym_demangle(const struct general_symbol_info *gsymbol) { + return DD_(demangle_d)(gsymbol->name); +} diff --exclude=CVS -urN current/gdb/d-lang.h current-demangle_d/gdb/d-lang.h --- current/gdb/d-lang.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/d-lang.h 2006-04-22 18:22:35.000000000 +0200 @@ -0,0 +1,37 @@ +/* C language support definitions for GDB, the GNU debugger. + Copyright 1992, 1994, 1995, 1996, 1997, 1998, 2000, 2002 + Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + + +#if !defined (D_LANG_H) +#define D_LANG_H 1 + +#include "symtab.h" + +/***************************** + D Language stuff +******************************/ + +char* d_demangle(const char* mangled, int options); + +char* d_sym_demangle(const struct general_symbol_info *gsymbol); + + +#endif /* !defined (D_LANG_H) */ diff --exclude=CVS -urN current/gdb/dwarf2read.c current-demangle_d/gdb/dwarf2read.c --- current/gdb/dwarf2read.c 2006-04-22 19:12:36.000000000 +0200 +++ current-demangle_d/gdb/dwarf2read.c 2006-04-22 18:22:35.000000000 +0200 @@ -6153,6 +6153,9 @@ case DW_LANG_C_plus_plus: cu->language = language_cplus; break; + case DW_LANG_D: + cu->language = language_d; + break; case DW_LANG_Fortran77: case DW_LANG_Fortran90: case DW_LANG_Fortran95: @@ -6631,7 +6634,7 @@ file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); line_ptr += bytes_read; fe = &lh->file_names[file - 1]; - if (fe->dir_index) + if (fe->dir_index && lh->include_dirs != NULL) dir = lh->include_dirs[fe->dir_index - 1]; if (!decode_for_pst_p) diff --exclude=CVS -urN current/gdb/language.c current-demangle_d/gdb/language.c --- current/gdb/language.c 2005-12-17 23:34:01.000000000 +0100 +++ current-demangle_d/gdb/language.c 2006-04-22 18:22:35.000000000 +0200 @@ -539,6 +539,7 @@ { case language_c: case language_cplus: + case language_d: case language_objc: if (TYPE_CODE (t1) == TYPE_CODE_FLT) return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ? @@ -650,6 +651,7 @@ { case language_c: case language_cplus: + case language_d: case language_objc: return (TYPE_CODE (type) != TYPE_CODE_INT) && (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1; @@ -690,6 +692,7 @@ case language_c: case language_cplus: + case language_d: case language_objc: return (TYPE_CODE (type) == TYPE_CODE_INT) && TYPE_LENGTH (type) == sizeof (char) @@ -712,6 +715,7 @@ case language_c: case language_cplus: + case language_d: case language_objc: /* C does not have distinct string type. */ return (0); @@ -731,6 +735,7 @@ { case language_c: case language_cplus: + case language_d: case language_objc: /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such @@ -804,6 +809,7 @@ } return builtin_type_f_logical_s2; case language_cplus: + case language_d: case language_pascal: if (current_language->la_language==language_cplus) {sym = lookup_symbol ("bool", NULL, VAR_DOMAIN, NULL, NULL);} diff --exclude=CVS -urN current/gdb/Makefile.in current-demangle_d/gdb/Makefile.in --- current/gdb/Makefile.in 2006-04-22 19:12:35.000000000 +0200 +++ current-demangle_d/gdb/Makefile.in 2006-04-22 18:24:03.000000000 +0200 @@ -518,7 +518,7 @@ c-exp.y c-lang.c c-typeprint.c c-valprint.c \ charset.c cli-out.c coffread.c coff-pe-read.c \ complaints.c completer.c corefile.c \ - cp-abi.c cp-support.c cp-namespace.c cp-valprint.c \ + cp-abi.c cp-support.c cp-namespace.c cp-valprint.c d-lang.c \ cp-name-parser.y \ dbxread.c demangle.c dictionary.c disasm.c doublest.c dummy-frame.c \ dwarfread.c dwarf2expr.c dwarf2loc.c dwarf2read.c dwarf2-frame.c \ @@ -662,6 +662,7 @@ completer_h = completer.h cp_abi_h = cp-abi.h cp_support_h = cp-support.h $(symtab_h) +d_lang_h = d-lang.h $(symtab_h) dcache_h = dcache.h defs_h = defs.h $(config_h) $(ansidecl_h) $(gdb_locale_h) $(gdb_signals_h) \ $(libiberty_h) $(bfd_h) $(ui_file_h) $(xm_h) $(nm_h) $(tm_h) \ @@ -934,7 +935,7 @@ dbxread.o coffread.o coff-pe-read.o elfread.o \ dwarfread.o dwarf2read.o mipsread.o stabsread.o corefile.o \ dwarf2expr.o dwarf2loc.o dwarf2-frame.o \ - ada-lang.o c-lang.o f-lang.o objc-lang.o \ + ada-lang.o c-lang.o d-lang.o f-lang.o objc-lang.o \ ui-out.o cli-out.o \ varobj.o wrapper.o \ jv-lang.o jv-valprint.o jv-typeprint.o \ @@ -1874,6 +1875,9 @@ c-valprint.o: c-valprint.c $(defs_h) $(gdb_string_h) $(symtab_h) \ $(gdbtypes_h) $(expression_h) $(value_h) $(valprint_h) $(language_h) \ $(c_lang_h) $(cp_abi_h) $(target_h) +d-lang.o: d-lang.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \ + $(parser_defs_h) $(language_h) $(c_lang_h) $(valprint_h) \ + $(macroscope_h) $(gdb_assert_h) $(charset_h) $(gdb_string_h) # OBSOLETE d10v-tdep.o: d10v-tdep.c dbug-rom.o: dbug-rom.c $(defs_h) $(gdbcore_h) $(target_h) $(monitor_h) \ $(serial_h) $(regcache_h) $(m68k_tdep_h) @@ -2710,7 +2714,7 @@ $(gdb_obstack_h) $(exceptions_h) $(language_h) $(bcache_h) \ $(block_h) $(gdb_regex_h) $(gdb_stat_h) $(dictionary_h) \ $(gdb_string_h) $(readline_h) -symtab.o: symtab.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \ +symtab.o: symtab.c $(defs_h) $(d_lang_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \ $(frame_h) $(target_h) $(value_h) $(symfile_h) $(objfiles_h) \ $(gdbcmd_h) $(call_cmds_h) $(gdb_regex_h) $(expression_h) \ $(language_h) $(demangle_h) $(inferior_h) $(linespec_h) $(source_h) \ diff --exclude=CVS -urN current/gdb/symfile.c current-demangle_d/gdb/symfile.c --- current/gdb/symfile.c 2006-02-25 05:36:39.000000000 +0100 +++ current-demangle_d/gdb/symfile.c 2006-04-22 18:22:35.000000000 +0200 @@ -2358,6 +2358,7 @@ filename_language_table = xmalloc (fl_table_size * sizeof (*filename_language_table)); add_filename_language (".c", language_c); + add_filename_language (".d", language_d); add_filename_language (".C", language_cplus); add_filename_language (".cc", language_cplus); add_filename_language (".cp", language_cplus); diff --exclude=CVS -urN current/gdb/symtab.c current-demangle_d/gdb/symtab.c --- current/gdb/symtab.c 2005-12-17 23:34:03.000000000 +0100 +++ current-demangle_d/gdb/symtab.c 2006-04-22 18:22:35.000000000 +0200 @@ -42,6 +42,7 @@ #include "filenames.h" /* for FILENAME_CMP */ #include "objc-lang.h" #include "ada-lang.h" +#include "d-lang.h" #include "hashtab.h" @@ -405,6 +406,7 @@ { gsymbol->language = language; if (gsymbol->language == language_cplus + || gsymbol->language == language_d || gsymbol->language == language_java || gsymbol->language == language_objc) { @@ -451,6 +453,15 @@ if (gsymbol->language == language_unknown) gsymbol->language = language_auto; + if (gsymbol->language == language_d + || gsymbol->language == language_auto) { + demangled = d_demangle(mangled, 0); + if (demangled != NULL) { + gsymbol->language = language_d; + return demangled; + } + } + if (gsymbol->language == language_objc || gsymbol->language == language_auto) { @@ -610,6 +621,7 @@ demangled = symbol_find_demangled_name (gsymbol, mangled); if (gsymbol->language == language_cplus + || gsymbol->language == language_d || gsymbol->language == language_java || gsymbol->language == language_objc) { @@ -639,6 +651,7 @@ switch (gsymbol->language) { case language_cplus: + case language_d: case language_java: case language_objc: if (gsymbol->language_specific.cplus_specific.demangled_name != NULL) @@ -664,6 +677,7 @@ switch (gsymbol->language) { case language_cplus: + case language_d: case language_java: case language_objc: if (gsymbol->language_specific.cplus_specific.demangled_name != NULL) @@ -1023,7 +1037,7 @@ modified_name = name; - /* If we are using C++ or Java, demangle the name before doing a lookup, so + /* If we are using C++, D, or Java, demangle the name before doing a lookup, so we can always binary search. */ if (current_language->la_language == language_cplus) { @@ -1035,6 +1049,16 @@ needtofreename = 1; } } + else if (current_language->la_language == language_d) + { + demangled_name = d_demangle (name, 0); + if (demangled_name) + { + mangled_name = name; + modified_name = demangled_name; + needtofreename = 1; + } + } else if (current_language->la_language == language_java) { demangled_name = cplus_demangle (name, Dateien current/gdb/testsuite/gdb.asm/asm-source und current-demangle_d/gdb/testsuite/gdb.asm/asm-source sind verschieden. Dateien current/gdb/testsuite/gdb.base/advance und current-demangle_d/gdb/testsuite/gdb.base/advance sind verschieden. Dateien current/gdb/testsuite/gdb.base/annota3 und current-demangle_d/gdb/testsuite/gdb.base/annota3 sind verschieden. Dateien current/gdb/testsuite/gdb.base/args und current-demangle_d/gdb/testsuite/gdb.base/args sind verschieden. Dateien current/gdb/testsuite/gdb.base/arrayidx und current-demangle_d/gdb/testsuite/gdb.base/arrayidx sind verschieden. Dateien current/gdb/testsuite/gdb.base/async und current-demangle_d/gdb/testsuite/gdb.base/async sind verschieden. Dateien current/gdb/testsuite/gdb.base/attach und current-demangle_d/gdb/testsuite/gdb.base/attach sind verschieden. Dateien current/gdb/testsuite/gdb.base/attach2 und current-demangle_d/gdb/testsuite/gdb.base/attach2 sind verschieden. Dateien current/gdb/testsuite/gdb.base/auxv und current-demangle_d/gdb/testsuite/gdb.base/auxv sind verschieden. Dateien current/gdb/testsuite/gdb.base/auxv.gcore und current-demangle_d/gdb/testsuite/gdb.base/auxv.gcore sind verschieden. Dateien current/gdb/testsuite/gdb.base/bang! und current-demangle_d/gdb/testsuite/gdb.base/bang! sind verschieden. Dateien current/gdb/testsuite/gdb.base/bfp-test und current-demangle_d/gdb/testsuite/gdb.base/bfp-test sind verschieden. Dateien current/gdb/testsuite/gdb.base/bigcore und current-demangle_d/gdb/testsuite/gdb.base/bigcore sind verschieden. Dateien current/gdb/testsuite/gdb.base/bigcore.corefile und current-demangle_d/gdb/testsuite/gdb.base/bigcore.corefile sind verschieden. Dateien current/gdb/testsuite/gdb.base/bitfields2 und current-demangle_d/gdb/testsuite/gdb.base/bitfields2 sind verschieden. Dateien current/gdb/testsuite/gdb.base/breako2 und current-demangle_d/gdb/testsuite/gdb.base/breako2 sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-tc und current-demangle_d/gdb/testsuite/gdb.base/call-sc-tc sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-td und current-demangle_d/gdb/testsuite/gdb.base/call-sc-td sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-tf und current-demangle_d/gdb/testsuite/gdb.base/call-sc-tf sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-ti und current-demangle_d/gdb/testsuite/gdb.base/call-sc-ti sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-tl und current-demangle_d/gdb/testsuite/gdb.base/call-sc-tl sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-tll und current-demangle_d/gdb/testsuite/gdb.base/call-sc-tll sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-ts und current-demangle_d/gdb/testsuite/gdb.base/call-sc-ts sind verschieden.