*** empty log message ***
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@1046 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
23a520cadc
commit
9f59bfcfae
23 changed files with 1101 additions and 354 deletions
340
SWIG/Tools/WAD/COPYING
Normal file
340
SWIG/Tools/WAD/COPYING
Normal file
|
|
@ -0,0 +1,340 @@
|
||||||
|
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.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) 19yy <name of author>
|
||||||
|
|
||||||
|
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) 19yy 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.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 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.
|
||||||
78
SWIG/Tools/WAD/HACK
Normal file
78
SWIG/Tools/WAD/HACK
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
The WAD Developers Guide
|
||||||
|
|
||||||
|
David Beazley (beazley@cs.uchicago.edu)
|
||||||
|
|
||||||
|
$Header$
|
||||||
|
|
||||||
|
1. Introduction
|
||||||
|
|
||||||
|
This short document is intended for anyone who feels inclined to work
|
||||||
|
on WAD and make improvements. It is by no means complete. However,
|
||||||
|
it contains random commentary on the current implementation.
|
||||||
|
|
||||||
|
2. A brief word on the execution environment
|
||||||
|
|
||||||
|
Because WAD is embedded in the same application it is intended to
|
||||||
|
debug, it must take an extremely conservative approach to its own
|
||||||
|
execution environment. Specifically, it can not rely upon the correct
|
||||||
|
operation of C library--especially with respect to memory management
|
||||||
|
and other basic operations. Because of this, the implementation of
|
||||||
|
WAD makes every effort to be as self-contained as possible--thus
|
||||||
|
minimizing its exposure to corrupted libraries in the faulting
|
||||||
|
application. Closely related to this, WAD does not rely on any
|
||||||
|
third-party libraries (e.g., libbfd) since it is almost impossible to
|
||||||
|
fully verify the way in which such libraries might use other programming
|
||||||
|
libraries.
|
||||||
|
|
||||||
|
With that said, you might keep the following rules in mind:
|
||||||
|
|
||||||
|
rule 1: Trust nothing--it might be broken.
|
||||||
|
rule 2: When in doubt, see rule 1.
|
||||||
|
|
||||||
|
(Of course, we can probably get away with assuming that the OS isn't
|
||||||
|
hosed).
|
||||||
|
|
||||||
|
3. Memory management
|
||||||
|
|
||||||
|
There are two problems here: first, the dynamic memory
|
||||||
|
allocator may be corrupted or broken (e.g., as might occur when
|
||||||
|
you double-free memory or free memory not allocated by malloc).
|
||||||
|
Second, the WAD signal handler prefers to execute own on its own
|
||||||
|
signal handling stack. This stack is of limited size so it is not
|
||||||
|
a reliable place to put large amounts of data.
|
||||||
|
|
||||||
|
Small buffers and scratch areas are managed through the use of static
|
||||||
|
variables allocated in the WAD data-segment.
|
||||||
|
|
||||||
|
For dynamic memory management, WAD provides its own memory allocator
|
||||||
|
in the function wad_malloc(). This function allocates memory by using
|
||||||
|
mmap() to grab anonymous memory regions (mapped to /dev/zero). This
|
||||||
|
memory is currently allocated in chunks of 64Kbytes as needed.
|
||||||
|
|
||||||
|
To simplify the implementation and prevent potential memory problems
|
||||||
|
in WAD itself, WAD never releases the memory that it allocates. There
|
||||||
|
is no wad_free() operation nor is there any way to release all of the
|
||||||
|
memory previously allocated.
|
||||||
|
|
||||||
|
Although memory is never released, WAD tries to intern commonly used
|
||||||
|
strings. An internal string hash is built as WAD runs and in most
|
||||||
|
cases, each string is mapped to a single instance of the string in
|
||||||
|
this hash table. The function wad_string_lookup(char *s) is used to
|
||||||
|
return a pointer to the string s in the hash table. If no entry
|
||||||
|
exists, it is created and a pointer is returned.
|
||||||
|
|
||||||
|
4. I/O
|
||||||
|
|
||||||
|
It is probably a bad idea to use buffered I/O with WAD. This may
|
||||||
|
result in implicit calls to malloc() and related functions.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -5,8 +5,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -49,18 +62,24 @@ extern "C" {
|
||||||
|
|
||||||
extern int wad_memory_init();
|
extern int wad_memory_init();
|
||||||
extern void *wad_malloc(int nbytes);
|
extern void *wad_malloc(int nbytes);
|
||||||
extern void wad_release_memory();
|
|
||||||
extern char *wad_strdup(const char *c);
|
extern char *wad_strdup(const char *c);
|
||||||
extern void wad_memory_debug();
|
extern void wad_memory_debug();
|
||||||
|
extern void wad_memcpy(void *t, const void *s, unsigned len);
|
||||||
|
|
||||||
/* --- Low level string handling --- */
|
/* --- Low level string handling --- */
|
||||||
|
|
||||||
extern char *wad_string_lookup(char *s);
|
extern char *wad_string_lookup(char *s);
|
||||||
extern void wad_string_debug();
|
extern void wad_string_debug();
|
||||||
|
extern char *wad_strcpy(char *t, const char *s);
|
||||||
|
extern char *wad_strcat(char *t, const char *s);
|
||||||
|
extern int wad_strlen(const char *s);
|
||||||
|
|
||||||
/* --- I/O, Debugging --- */
|
/* --- I/O, Debugging --- */
|
||||||
|
|
||||||
extern void wad_printf(const char *fmt, ...);
|
extern void wad_printf(const char *fmt, ...);
|
||||||
|
extern char *wad_format_hex(unsigned long u, int leading);
|
||||||
|
extern char *wad_format_unsigned(unsigned long u, int width);
|
||||||
|
extern char *wad_format_signed(long s, int width);
|
||||||
|
|
||||||
/* --- Memory segments --- */
|
/* --- Memory segments --- */
|
||||||
typedef struct WadSegment {
|
typedef struct WadSegment {
|
||||||
|
|
@ -161,6 +180,7 @@ typedef struct WadFrame {
|
||||||
/* Symbol table information for PC */
|
/* Symbol table information for PC */
|
||||||
|
|
||||||
char *sym_name; /* Symbol name */
|
char *sym_name; /* Symbol name */
|
||||||
|
int sym_nlen; /* Symbol name length */
|
||||||
char *sym_file; /* Source file (if any) */
|
char *sym_file; /* Source file (if any) */
|
||||||
unsigned long sym_base; /* Symbol base address */
|
unsigned long sym_base; /* Symbol base address */
|
||||||
unsigned long sym_size; /* Symbol size */
|
unsigned long sym_size; /* Symbol size */
|
||||||
|
|
@ -173,6 +193,7 @@ typedef struct WadFrame {
|
||||||
int loc_line; /* Source line */
|
int loc_line; /* Source line */
|
||||||
|
|
||||||
/* Debugging information */
|
/* Debugging information */
|
||||||
|
int debug_check; /* Checked debugging information */
|
||||||
int debug_nargs; /* Number of arguments */
|
int debug_nargs; /* Number of arguments */
|
||||||
WadLocal *debug_args; /* Arguments */
|
WadLocal *debug_args; /* Arguments */
|
||||||
WadLocal *debug_lastarg; /* Last argument */
|
WadLocal *debug_lastarg; /* Last argument */
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "Python.h"
|
#include "Python.h"
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,46 @@
|
||||||
WAD (Wrapped Application Debugger)
|
WAD (Wrapped Application Debugger)
|
||||||
|
|
||||||
David M. Beazley
|
Copyright (C) 2001
|
||||||
Department of Computer Science
|
|
||||||
University of Chicago
|
|
||||||
Chicago, IL 60637
|
|
||||||
beazley@cs.uchicago.edu
|
|
||||||
|
|
||||||
Copyright (C) 2000-2001
|
Author(s):
|
||||||
University of Chicago
|
David M. Beazley (beazley@cs.uchicago.edu)
|
||||||
All Rights Reserved
|
|
||||||
|
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
|
||||||
|
|
||||||
$Header$
|
$Header$
|
||||||
|
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
!!!!!!!! DISCLAIMER !!!!!!!!
|
!!!!!!!! DISCLAIMER !!!!!!!!
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
THIS IS EXPERIMENTAL UNSUPPORTED SOFTWARE THAT UTILIZES A HORRIBLE MIX
|
THIS IS EXPERIMENTAL UNMAINTAINED RESEARCH SOFTWARE. IT IS NOT
|
||||||
OF LOW-LEVEL C, C++, AND ASSEMBLY CODE. IT IS NOT PORTABLE, IT HAS
|
PORTABLE, IT HAS NOT BEEN EXHAUSTIVELY TESTED, AND IT MIGHT NOT WORK
|
||||||
NOT BEEN EXHAUSTIVELY TESTED, AND IT MIGHT NOT WORK AT ALL. PLEASE KEEP
|
AT ALL. PLEASE KEEP AWAY FROM SMALL CHILDREN, PETS, NUCLEAR REACTORS,
|
||||||
AWAY FROM SMALL CHILDREN, PETS, NUCLEAR REACTORS, AIR-TRAFFIC CONTROL,
|
AIR-TRAFFIC CONTROL, AND VOTING MACHINES.
|
||||||
AND VOTING MACHINES. SIDE EFFECTS MAY INCLUDE NAUSEA, VOMITING, AND
|
|
||||||
HEADACHE. OTHER THAN THIS, IT'S PERFECTLY SAFE.
|
|
||||||
|
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
THIS SOFTWARE MAY ONLY BE USED FOR NON-COMMERCIAL PURPOSES. IT IS
|
||||||
!!!!!!!! SUPPORTED PLATFORMS !!!!!!!!
|
DISTRIBUTED UNDER THE TERMS OF THE GNU PUBLIC LICENSE WITH THE HOPE
|
||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
THAT OTHERS FIND IT TO BE INTERESTING.
|
||||||
|
|
||||||
This software is only known to work with 32-bit applications on Sun
|
0. Supported Platforms
|
||||||
Sparc Solaris 2.8 and recent i386-Linux systems. In addition, there
|
|
||||||
are numerous issues concerning the interaction of this software with
|
This software is currently only known to work with 32-bit applications
|
||||||
signal handling, thread libraries, and compilers. Please read this
|
on Sun Sparc Solaris 2.8 and recent i386-Linux systems. In addition,
|
||||||
entire document before proceeding.
|
there are numerous issues concerning the interaction of this software
|
||||||
|
with signal handling, thread libraries, and compilers. Please read
|
||||||
|
this entire document before proceeding.
|
||||||
|
|
||||||
1. Introduction
|
1. Introduction
|
||||||
|
|
||||||
|
|
@ -43,14 +52,14 @@ with stand-alone C programs.
|
||||||
|
|
||||||
The primary goal of this system is to explore an alternative approach
|
The primary goal of this system is to explore an alternative approach
|
||||||
to mixed scripting-compiled debugging. It requires no modifications
|
to mixed scripting-compiled debugging. It requires no modifications
|
||||||
or recompilation of existing software--only relinking. Therefore, it
|
or recompilation of existing software. Therefore, it should be
|
||||||
should be relatively easy to try out. Feedback is welcome. Contributions
|
relatively easy to try out. Feedback is welcome. Contributions and
|
||||||
and modifications are even more welcome.
|
modifications are even more welcome.
|
||||||
|
|
||||||
2. Compilation and Installation
|
2. Compilation and Installation
|
||||||
|
|
||||||
WAD is not particularly portable (for obvious reasons). At this time,
|
WAD is not particularly portable and at this time, only two platforms
|
||||||
only two platforms are supported: Sun Sparc Solaris and i386-Linux.
|
are supported: Sun Sparc Solaris and i386-Linux.
|
||||||
|
|
||||||
Installation is as follows:
|
Installation is as follows:
|
||||||
|
|
||||||
|
|
@ -96,7 +105,7 @@ Notes:
|
||||||
them in non-traditional locations.
|
them in non-traditional locations.
|
||||||
|
|
||||||
- The Linux version has only been tested with 2.2-12 and 2.2-14 kernels
|
- The Linux version has only been tested with 2.2-12 and 2.2-14 kernels
|
||||||
and the RedHat 6.0 distribution. Your mileage may vary.
|
and the RedHat 6.x distribution. Your mileage may vary.
|
||||||
|
|
||||||
3. Using WAD
|
3. Using WAD
|
||||||
|
|
||||||
|
|
@ -172,6 +181,10 @@ WAD_NOSTACK - Do NOT use an alternative signal handling stack.
|
||||||
WAD_ONESHOT - Disable WAD signal handler after first signal has
|
WAD_ONESHOT - Disable WAD signal handler after first signal has
|
||||||
been received.
|
been received.
|
||||||
|
|
||||||
|
WAD_DEBUG_MEMORY - Print information about WAD memory use.
|
||||||
|
|
||||||
|
WAD_DEBUG_STRINGS - Print information about WAD string manager.
|
||||||
|
|
||||||
5. Platform Specific Issues
|
5. Platform Specific Issues
|
||||||
|
|
||||||
General:
|
General:
|
||||||
|
|
@ -210,7 +223,7 @@ Linux:
|
||||||
some specific thread-based issues that may arise:
|
some specific thread-based issues that may arise:
|
||||||
|
|
||||||
1. WAD causes the program to crash immediately upon startup.
|
1. WAD causes the program to crash immediately upon startup.
|
||||||
This appears to be caused by a bug in in the implemenation
|
This appears to be caused by a bug in in the implementation
|
||||||
of sigaction() and the initialization of signals. This
|
of sigaction() and the initialization of signals. This
|
||||||
only occurs if WAD is directly linked to an executable
|
only occurs if WAD is directly linked to an executable
|
||||||
using threads. It does not occur when WAD is dynamically
|
using threads. It does not occur when WAD is dynamically
|
||||||
|
|
@ -265,6 +278,8 @@ mechanism. Standard functions tend to just exit. The WAD handler
|
||||||
produces a C stack trace and produces a Perl stack trace using some
|
produces a C stack trace and produces a Perl stack trace using some
|
||||||
code derived from the sigtrap module.
|
code derived from the sigtrap module.
|
||||||
|
|
||||||
|
Note: 3/10/01 - Perl support is currently broken.
|
||||||
|
|
||||||
7. Testing and Examples
|
7. Testing and Examples
|
||||||
|
|
||||||
The Test directory contains some very simple code for testing WAD. In the
|
The Test directory contains some very simple code for testing WAD. In the
|
||||||
|
|
@ -306,27 +321,49 @@ The scripts debug.py, debug.tcl, debug.pl can be used to test these extensions.
|
||||||
|
|
||||||
8. Documentation
|
8. Documentation
|
||||||
|
|
||||||
No official documentation exists at this time. However, the Papers directory contains
|
No official documentation exists at this time. However, the Papers
|
||||||
two conference papers that describe WAD's design and high-level operation.
|
directory contains two conference papers that describe WAD's design
|
||||||
|
and high-level operation. Slides from the Python9 talk are also included.
|
||||||
|
|
||||||
9. To-Do
|
9. To-Do
|
||||||
|
|
||||||
The current implementation is fairly messy and undergoing constant
|
If you find WAD to be interesting or useful, there are a variety of
|
||||||
change. Here is the short list:
|
ways to contribute. Here is the short to-do list:
|
||||||
|
|
||||||
|
- Better register management. Try to implement in a more portable
|
||||||
|
way. Add some support code for recovering local variables
|
||||||
|
that happen to be stored in registers.
|
||||||
|
|
||||||
|
- Add heuristic for recovering functions called through an
|
||||||
|
-fomit-frame-pointer compiler optimization scheme. This
|
||||||
|
can probably be determined by looking at the function preamble
|
||||||
|
machine code. Then one can back-trace to the calling function
|
||||||
|
and look at it's preamble.
|
||||||
|
|
||||||
|
- Continued clean up and modularization of the core. Many of the
|
||||||
|
internal APIs could be greatly improved.
|
||||||
|
|
||||||
- Continued clean up and modularization of the core.
|
|
||||||
- Support for ELF64 linking format.
|
- Support for ELF64 linking format.
|
||||||
|
|
||||||
|
- Support for DWARF2 debugging data.
|
||||||
|
|
||||||
- Improved support for stack-overflow and heap-corruption. Although WAD
|
- Improved support for stack-overflow and heap-corruption. Although WAD
|
||||||
probably won't be able to recover, it still might be able to produce some
|
probably won't be able to recover, it still might be able to produce some
|
||||||
informative diagnostics.
|
informative diagnostics.
|
||||||
|
|
||||||
- Removal of printf() and other high-level library calls which may not
|
- Removal of printf() and other high-level library calls which may not
|
||||||
operate with a corrupted heap.
|
operate with a corrupted heap.
|
||||||
|
|
||||||
- Better integration with scripting languages.
|
- Better integration with scripting languages.
|
||||||
|
|
||||||
- Support for new platforms.
|
- Support for new platforms.
|
||||||
|
|
||||||
- Support for new scripting languages.
|
- Support for new scripting languages.
|
||||||
|
|
||||||
Dave Beazley
|
Please contact me if you are interested in working on any of these projects.
|
||||||
January 3, 2001
|
|
||||||
|
Dave Beazley (beazley@cs.uchicago.edu)
|
||||||
|
March 10, 2001
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,25 +10,25 @@
|
||||||
WADSRCS = string.c vars.c io.c memory.c return.c default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
|
WADSRCS = string.c vars.c io.c memory.c return.c default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
|
||||||
WADOBJS = string.o vars.o io.o memory.o return.o default.o stack.o stab.o elf.o object.o signal.o segment.o init.o
|
WADOBJS = string.o vars.o io.o memory.o return.o default.o stack.o stab.o elf.o object.o signal.o segment.o init.o
|
||||||
INCLUDE = -I../Include -I. $(SINCLUDE)
|
INCLUDE = -I../Include -I. $(SINCLUDE)
|
||||||
WADOPT = -DWAD_SOLARIS
|
WADOPT = -DWAD_LINUX
|
||||||
|
|
||||||
|
|
||||||
# Location of your Perl installation
|
# Location of your Perl installation
|
||||||
PERLINCLUDE = -I/usr/perl5/5.00503/sun4-solaris/CORE
|
PERLINCLUDE = -I/usr/lib/perl5/5.00503/i386-linux/CORE
|
||||||
PERLSRCS = wadpl.cxx
|
PERLSRCS = wadpl.cxx
|
||||||
PERLOBJS = wadpl.o
|
PERLOBJS = wadpl.o
|
||||||
|
|
||||||
# C Compiler
|
# C Compiler
|
||||||
CC = cc
|
CC = gcc -Wall
|
||||||
CFLAGS = #
|
CFLAGS = #-fpic
|
||||||
|
|
||||||
# C++ Compiler
|
# C++ Compiler
|
||||||
CXX = CC
|
CXX = c++
|
||||||
CXXFLAGS = #-Kpic
|
CXXFLAGS = #-fpic
|
||||||
|
|
||||||
# Linking options
|
# Linking options
|
||||||
CLINK =
|
CLINK =
|
||||||
CXXLINK = CC -G
|
CXXLINK = g++ -shared
|
||||||
|
|
||||||
# AR
|
# AR
|
||||||
AR = ar
|
AR = ar
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -20,7 +33,6 @@
|
||||||
|
|
||||||
char *wad_arg_string(WadFrame *frame) {
|
char *wad_arg_string(WadFrame *frame) {
|
||||||
static char str[1024];
|
static char str[1024];
|
||||||
static char temp[64];
|
|
||||||
WadLocal *wp;
|
WadLocal *wp;
|
||||||
long *stack;
|
long *stack;
|
||||||
long *nextstack;
|
long *nextstack;
|
||||||
|
|
@ -58,20 +70,21 @@ char *wad_arg_string(WadFrame *frame) {
|
||||||
|
|
||||||
#ifdef WAD_SOLARIS
|
#ifdef WAD_SOLARIS
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
sprintf(temp,"0x%x", stack[8+i]);
|
wad_strcpy(temp,"0x");
|
||||||
strcat(str,temp);
|
wad_strcat(temp,wad_format_hex(stack[8+1],0));
|
||||||
|
wad_strcat(str,temp);
|
||||||
if (i < 5)
|
if (i < 5)
|
||||||
strcat(str,",");
|
wad_strcat(str,",");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* We were able to get some argument information out the debugging table */
|
/* We were able to get some argument information out the debugging table */
|
||||||
wp = frame->debug_args;
|
wp = frame->debug_args;
|
||||||
for (i = 0; i < frame->debug_nargs; i++, wp = wp->next) {
|
for (i = 0; i < frame->debug_nargs; i++, wp = wp->next) {
|
||||||
strcat(str,wp->name);
|
wad_strcat(str,wp->name);
|
||||||
strcat(str,"=");
|
wad_strcat(str,"=");
|
||||||
strcat(str,wad_format_var(wp));
|
wad_strcat(str,wad_format_var(wp));
|
||||||
if (i < (frame->debug_nargs-1)) strcat(str,",");
|
if (i < (frame->debug_nargs-1)) wad_strcat(str,",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
|
@ -120,7 +133,7 @@ char *wad_load_source(char *path, int line) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
strcpy(src_path,path);
|
wad_strcpy(src_path,path);
|
||||||
}
|
}
|
||||||
n = 0;
|
n = 0;
|
||||||
start = src_file;
|
start = src_file;
|
||||||
|
|
@ -156,7 +169,6 @@ void wad_release_source() {
|
||||||
|
|
||||||
char *wad_debug_src_string(WadFrame *f, int window) {
|
char *wad_debug_src_string(WadFrame *f, int window) {
|
||||||
static char temp[16384];
|
static char temp[16384];
|
||||||
char ntemp[64];
|
|
||||||
|
|
||||||
if (f->loc_srcfile && strlen(f->loc_srcfile) && (f->loc_line > 0)) {
|
if (f->loc_srcfile && strlen(f->loc_srcfile) && (f->loc_line > 0)) {
|
||||||
char *line, *c;
|
char *line, *c;
|
||||||
|
|
@ -167,22 +179,22 @@ char *wad_debug_src_string(WadFrame *f, int window) {
|
||||||
if (first < 1) first = 1;
|
if (first < 1) first = 1;
|
||||||
line = wad_load_source(f->loc_srcfile,first);
|
line = wad_load_source(f->loc_srcfile,first);
|
||||||
if (line) {
|
if (line) {
|
||||||
strcpy(temp,f->loc_srcfile);
|
wad_strcpy(temp,f->loc_srcfile);
|
||||||
strcat(temp,", line ");
|
wad_strcat(temp,", line ");
|
||||||
sprintf(ntemp,"%d\n\n", f->loc_line);
|
wad_strcat(temp,wad_format_signed(f->loc_line,-1));
|
||||||
strcat(temp,ntemp);
|
wad_strcat(temp,"\n\n");
|
||||||
for (i = first; i <= last; i++) {
|
for (i = first; i <= last; i++) {
|
||||||
if (i == f->loc_line) strcat(temp," => ");
|
if (i == f->loc_line) wad_strcat(temp," => ");
|
||||||
else strcat(temp," ");
|
else wad_strcat(temp," ");
|
||||||
c = strchr(line,'\n');
|
c = strchr(line,'\n');
|
||||||
if (c) {
|
if (c) {
|
||||||
*c = 0;
|
*c = 0;
|
||||||
strcat(temp,line);
|
wad_strcat(temp,line);
|
||||||
strcat(temp,"\n");
|
wad_strcat(temp,"\n");
|
||||||
*c = '\n';
|
*c = '\n';
|
||||||
} else {
|
} else {
|
||||||
strcat(temp,line);
|
wad_strcat(temp,line);
|
||||||
strcat(temp,"\n");
|
wad_strcat(temp,"\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
line = c+1;
|
line = c+1;
|
||||||
|
|
@ -204,31 +216,34 @@ char *wad_debug_src_string(WadFrame *f, int window) {
|
||||||
void
|
void
|
||||||
wad_debug_make_strings(WadFrame *f) {
|
wad_debug_make_strings(WadFrame *f) {
|
||||||
static char msg[16384];
|
static char msg[16384];
|
||||||
char temp[1024];
|
|
||||||
while (f) {
|
while (f) {
|
||||||
sprintf(msg,"#%-3d 0x%08x in ", f->frameno, f->pc);
|
wad_strcpy(msg,"#");
|
||||||
strcat(msg, f->sym_name ? f->sym_name : "?");
|
wad_strcat(msg,wad_format_signed(f->frameno,3));
|
||||||
strcat(msg,"(");
|
wad_strcat(msg," 0x");
|
||||||
strcat(msg,wad_arg_string(f));
|
wad_strcat(msg,wad_format_hex(f->pc,1));
|
||||||
strcat(msg,")");
|
wad_strcat(msg," in ");
|
||||||
|
wad_strcat(msg, f->sym_name ? f->sym_name : "?");
|
||||||
|
wad_strcat(msg,"(");
|
||||||
|
wad_strcat(msg,wad_arg_string(f));
|
||||||
|
wad_strcat(msg,")");
|
||||||
if (f->loc_srcfile && strlen(f->loc_srcfile)) {
|
if (f->loc_srcfile && strlen(f->loc_srcfile)) {
|
||||||
strcat(msg," in '");
|
wad_strcat(msg," in '");
|
||||||
strcat(msg, wad_strip_dir(f->loc_srcfile));
|
wad_strcat(msg, wad_strip_dir(f->loc_srcfile));
|
||||||
strcat(msg,"'");
|
wad_strcat(msg,"'");
|
||||||
if (f->loc_line > 0) {
|
if (f->loc_line > 0) {
|
||||||
sprintf(temp,", line %d", f->loc_line);
|
wad_strcat(msg,", line ");
|
||||||
strcat(msg,temp);
|
wad_strcat(msg,wad_format_signed(f->loc_line,-1));
|
||||||
/* Try to locate the source file */
|
/* Try to locate the source file */
|
||||||
wad_debug_src_string(f, WAD_SRC_WINDOW);
|
wad_debug_src_string(f, WAD_SRC_WINDOW);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (f->loc_objfile && strlen(f->loc_objfile)) {
|
if (f->loc_objfile && strlen(f->loc_objfile)) {
|
||||||
strcat(msg," from '");
|
wad_strcat(msg," from '");
|
||||||
strcat(msg, wad_strip_dir(f->loc_objfile));
|
wad_strcat(msg, wad_strip_dir(f->loc_objfile));
|
||||||
strcat(msg,"'");
|
wad_strcat(msg,"'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strcat(msg,"\n");
|
wad_strcat(msg,"\n");
|
||||||
f->debug_str = wad_strdup(msg);
|
f->debug_str = wad_strdup(msg);
|
||||||
f = f->next;
|
f = f->next;
|
||||||
}
|
}
|
||||||
|
|
@ -239,8 +254,6 @@ wad_debug_make_strings(WadFrame *f) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void wad_default_callback(int signo, WadFrame *f, char *ret) {
|
void wad_default_callback(int signo, WadFrame *f, char *ret) {
|
||||||
char *fd;
|
|
||||||
WadFrame *fline = 0;
|
|
||||||
char *srcstr = 0;
|
char *srcstr = 0;
|
||||||
|
|
||||||
switch(signo) {
|
switch(signo) {
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -20,11 +33,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* --- What's needed here (high level interface) :
|
/* --- What's needed here (high level interface) :
|
||||||
|
|
||||||
- Mapping of addresses to symbols
|
- Mapping of addresses to symbols
|
||||||
- Mapping of symbols to file+line
|
- Mapping of symbols to file+line
|
||||||
- Parameter passing information?
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -37,8 +47,6 @@
|
||||||
|
|
||||||
int
|
int
|
||||||
wad_elf_check(WadObjectFile *wo) {
|
wad_elf_check(WadObjectFile *wo) {
|
||||||
int t;
|
|
||||||
|
|
||||||
if (strncmp((char *)wo->ptr,ELFMAG, SELFMAG) != 0)
|
if (strncmp((char *)wo->ptr,ELFMAG, SELFMAG) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
@ -247,6 +255,7 @@ int elf_search_section_sym(WadFrame *f, char *secname, char *strname) {
|
||||||
if (sym[i].st_shndx == 0) continue;
|
if (sym[i].st_shndx == 0) continue;
|
||||||
#endif
|
#endif
|
||||||
f->sym_name = name;
|
f->sym_name = name;
|
||||||
|
f->sym_nlen = strlen(name);
|
||||||
f->sym_base = base + sym[i].st_value;
|
f->sym_base = base + sym[i].st_value;
|
||||||
f->sym_size = sym[i].st_size;
|
f->sym_size = sym[i].st_size;
|
||||||
if (ELF32_ST_BIND(sym[i].st_info) == STB_LOCAL) {
|
if (ELF32_ST_BIND(sym[i].st_info) == STB_LOCAL) {
|
||||||
|
|
@ -330,7 +339,7 @@ wad_elf_debug_info(WadFrame *f) {
|
||||||
WadObjectFile *wo1, *wold;
|
WadObjectFile *wo1, *wold;
|
||||||
/* Hmmm. Might be in a different file */
|
/* Hmmm. Might be in a different file */
|
||||||
char objfile[MAX_PATH];
|
char objfile[MAX_PATH];
|
||||||
strcpy(objfile, f->loc_objfile);
|
wad_strcpy(objfile, f->loc_objfile);
|
||||||
wo1 = wad_object_load(objfile);
|
wo1 = wad_object_load(objfile);
|
||||||
if (wo1) {
|
if (wo1) {
|
||||||
wold = f->object;
|
wold = f->object;
|
||||||
|
|
@ -398,9 +407,12 @@ wad_find_symbol(WadFrame *f) {
|
||||||
|
|
||||||
void
|
void
|
||||||
wad_find_debug(WadFrame *f) {
|
wad_find_debug(WadFrame *f) {
|
||||||
if (f->object)
|
if (f->debug_check) return;
|
||||||
|
if (f->object) {
|
||||||
wad_elf_debug_info(f);
|
wad_elf_debug_info(f);
|
||||||
}
|
}
|
||||||
|
f->debug_check = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,92 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
/* Utility functions used to generate strings that are guaranteed not to
|
||||||
|
rely upon malloc() and related functions */
|
||||||
|
|
||||||
|
char *wad_format_hex(unsigned long u, int leading) {
|
||||||
|
static char digits[] = "0123456789abcdef";
|
||||||
|
static char result[64];
|
||||||
|
int i;
|
||||||
|
char *c;
|
||||||
|
c = &result[63];
|
||||||
|
*c = 0;
|
||||||
|
for (i = 0; i < (sizeof(unsigned long) << 1); i++) {
|
||||||
|
int digit;
|
||||||
|
if (!u || leading) {
|
||||||
|
digit = u & 0xf;
|
||||||
|
*(--c) = digits[digit];
|
||||||
|
}
|
||||||
|
u = u >> 4;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *wad_format_unsigned(unsigned long u, int width) {
|
||||||
|
static char result[128];
|
||||||
|
static char digits[] = "0123456789";
|
||||||
|
char *c, *w;
|
||||||
|
int count = 0;
|
||||||
|
int i;
|
||||||
|
c = &result[64];
|
||||||
|
while (u) {
|
||||||
|
int digit = u % 10;
|
||||||
|
*(--c) = digits[digit];
|
||||||
|
count++;
|
||||||
|
u = u / 10;
|
||||||
|
}
|
||||||
|
if (!count) {
|
||||||
|
*(--c) = '0';
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
w = &result[64];
|
||||||
|
for (i = count; i < width; i++) {
|
||||||
|
*(w++) = ' ';
|
||||||
|
}
|
||||||
|
*w = 0;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *wad_format_signed(signed long s, int width) {
|
||||||
|
static char result[128];
|
||||||
|
unsigned long u;
|
||||||
|
char *c = result;
|
||||||
|
if (s < 0) {
|
||||||
|
*(c++) = '-';
|
||||||
|
width--;
|
||||||
|
u = (unsigned long) (-s);
|
||||||
|
if (u == 0) {
|
||||||
|
u = (unsigned long) s;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
u = (unsigned long) s;
|
||||||
|
}
|
||||||
|
*c = 0;
|
||||||
|
wad_strcat(result, wad_format_unsigned(u,width));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void wad_printf(const char *fmt, ...) {
|
void wad_printf(const char *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2001. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -23,7 +36,6 @@ typedef struct _WadMemory {
|
||||||
} WadMemory;
|
} WadMemory;
|
||||||
|
|
||||||
static WadMemory *current = 0; /* Current memory block */
|
static WadMemory *current = 0; /* Current memory block */
|
||||||
static WadMemory *persistent = 0; /* Persistent memory data */
|
|
||||||
static int pagesize = 0; /* System page size */
|
static int pagesize = 0; /* System page size */
|
||||||
static int devzero = 0;
|
static int devzero = 0;
|
||||||
static int npalloc = 8; /* Number of pages per alloc */
|
static int npalloc = 8; /* Number of pages per alloc */
|
||||||
|
|
@ -110,26 +122,6 @@ void *wad_malloc(int nbytes) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* wad_release_memory()
|
|
||||||
*
|
|
||||||
* Releases all memory previously allocated by wad_malloc(). This is inherently
|
|
||||||
* dangerous.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void wad_release_memory() {
|
|
||||||
WadMemory *wm, *next;
|
|
||||||
|
|
||||||
return;
|
|
||||||
wm = current;
|
|
||||||
while (wm) {
|
|
||||||
next = wm->next;
|
|
||||||
munmap((char *) wm, wm->npages*pagesize);
|
|
||||||
wm = next;
|
|
||||||
}
|
|
||||||
current = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* wad_strdup()
|
* wad_strdup()
|
||||||
*
|
*
|
||||||
|
|
@ -140,10 +132,23 @@ char *wad_strdup(const char *c) {
|
||||||
char *t;
|
char *t;
|
||||||
if (!c) c = "";
|
if (!c) c = "";
|
||||||
t = (char *) wad_malloc(strlen(c)+1);
|
t = (char *) wad_malloc(strlen(c)+1);
|
||||||
strcpy(t,c);
|
wad_strcpy(t,c);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* wad_memcpy()
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void wad_memcpy(void *t, const void *s, unsigned len) {
|
||||||
|
char *tc, *sc;
|
||||||
|
int i;
|
||||||
|
tc = (char *) t;
|
||||||
|
sc = (char *) s;
|
||||||
|
for (i = 0; i < len; i++, tc++, sc++)
|
||||||
|
*tc = *sc;
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* wad_memory_debug()
|
* wad_memory_debug()
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
@ -159,6 +164,6 @@ void wad_memory_debug() {
|
||||||
inuse += m->last;
|
inuse += m->last;
|
||||||
m = m->next;
|
m = m->next;
|
||||||
}
|
}
|
||||||
printf("WAD: memory allocated %d bytes (%d bytes used).\n", total_alloc, inuse);
|
wad_printf("WAD: memory allocated %d bytes (%d bytes used).\n", total_alloc, inuse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -34,7 +47,6 @@ static WadFile *wad_files = 0; /* Linked list of loaded files *
|
||||||
/* private function to manage the loading of raw files into memory */
|
/* private function to manage the loading of raw files into memory */
|
||||||
static WadFile *
|
static WadFile *
|
||||||
load_file(const char *path) {
|
load_file(const char *path) {
|
||||||
int i;
|
|
||||||
int fd;
|
int fd;
|
||||||
WadFile *wf = wad_files;
|
WadFile *wf = wad_files;
|
||||||
|
|
||||||
|
|
@ -84,7 +96,6 @@ static WadObjectFile *wad_objects = 0; /* Linked list of object fil
|
||||||
|
|
||||||
void
|
void
|
||||||
wad_object_reset() {
|
wad_object_reset() {
|
||||||
int i;
|
|
||||||
WadFile *f = wad_files;
|
WadFile *f = wad_files;
|
||||||
if (wad_debug_mode & DEBUG_OBJECT) {
|
if (wad_debug_mode & DEBUG_OBJECT) {
|
||||||
wad_printf("wad: Releasing all files.\n");
|
wad_printf("wad: Releasing all files.\n");
|
||||||
|
|
@ -112,7 +123,6 @@ WadObjectFile *
|
||||||
wad_object_load(const char *path) {
|
wad_object_load(const char *path) {
|
||||||
WadObjectFile *wo;
|
WadObjectFile *wo;
|
||||||
WadFile *wf;
|
WadFile *wf;
|
||||||
int i;
|
|
||||||
WadObjectFile *wad_arobject_load(const char *path, const char *name);
|
WadObjectFile *wad_arobject_load(const char *path, const char *name);
|
||||||
|
|
||||||
if (wad_debug_mode & DEBUG_OBJECT) {
|
if (wad_debug_mode & DEBUG_OBJECT) {
|
||||||
|
|
@ -139,7 +149,7 @@ wad_object_load(const char *path) {
|
||||||
char *c;
|
char *c;
|
||||||
c = strchr(path,'(');
|
c = strchr(path,'(');
|
||||||
if (c) {
|
if (c) {
|
||||||
strcpy(realfile,path);
|
wad_strcpy(realfile,path);
|
||||||
c = strchr(realfile,'(');
|
c = strchr(realfile,'(');
|
||||||
*c = 0;
|
*c = 0;
|
||||||
objfile = c+1;
|
objfile = c+1;
|
||||||
|
|
@ -181,9 +191,6 @@ WadObjectFile *
|
||||||
wad_arobject_load(const char *arpath, const char *robjname) {
|
wad_arobject_load(const char *arpath, const char *robjname) {
|
||||||
WadObjectFile *wo;
|
WadObjectFile *wo;
|
||||||
WadFile *wf;
|
WadFile *wf;
|
||||||
int nf;
|
|
||||||
int fd;
|
|
||||||
int i;
|
|
||||||
int arlen;
|
int arlen;
|
||||||
char *arptr;
|
char *arptr;
|
||||||
struct ar_hdr *ah;
|
struct ar_hdr *ah;
|
||||||
|
|
@ -193,8 +200,8 @@ wad_arobject_load(const char *arpath, const char *robjname) {
|
||||||
int sobjname;
|
int sobjname;
|
||||||
char objname[MAX_PATH];
|
char objname[MAX_PATH];
|
||||||
|
|
||||||
strcpy(objname,robjname);
|
wad_strcpy(objname,robjname);
|
||||||
strcat(objname,"/");
|
wad_strcat(objname,"/");
|
||||||
sobjname = strlen(objname);
|
sobjname = strlen(objname);
|
||||||
|
|
||||||
wf = load_file(arpath);
|
wf = load_file(arpath);
|
||||||
|
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* segment_linux.c
|
|
||||||
*
|
|
||||||
* This file reads the virtual memory map on Linux machines.
|
|
||||||
* This file is not compiled directly, it is included in the
|
|
||||||
* segment.c file.
|
|
||||||
*
|
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
|
||||||
*
|
|
||||||
* Copyright (C) 2000. The University of Chicago
|
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
static char linux_firstsegment[1024];
|
|
||||||
static int linux_first = 1;
|
|
||||||
|
|
||||||
static int
|
|
||||||
segment_open() {
|
|
||||||
FILE *f;
|
|
||||||
f = fopen("/proc/self/maps", "r");
|
|
||||||
linux_first =1;
|
|
||||||
return (int) f;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
segment_read(int fd, WadSegment *s)
|
|
||||||
{
|
|
||||||
char pbuffer[1024];
|
|
||||||
char *c;
|
|
||||||
int len;
|
|
||||||
FILE *fs = (FILE *) fd;
|
|
||||||
c = fgets(pbuffer,1024,fs);
|
|
||||||
if (!c) return 0;
|
|
||||||
|
|
||||||
pbuffer[strlen(pbuffer)-1] = 0; /* Chop off endline */
|
|
||||||
|
|
||||||
/* Break up the field into records */
|
|
||||||
/* 0-8 : Starting address
|
|
||||||
9-17 : Ending Address
|
|
||||||
18 : r
|
|
||||||
19 : w
|
|
||||||
20 : x
|
|
||||||
21 : p
|
|
||||||
23-31 : Offset
|
|
||||||
49- : Filename */
|
|
||||||
|
|
||||||
len = strlen(pbuffer);
|
|
||||||
pbuffer[8] = 0;
|
|
||||||
pbuffer[17] = 0;
|
|
||||||
pbuffer[31] = 0;
|
|
||||||
if (len >= 49) {
|
|
||||||
s->mapname = wad_strdup(pbuffer+49);
|
|
||||||
s->mappath = s->mapname;
|
|
||||||
} else {
|
|
||||||
s->mapname = "";
|
|
||||||
s->mappath = s->mapname;
|
|
||||||
}
|
|
||||||
if (linux_first) {
|
|
||||||
strcpy(linux_firstsegment, s->mappath);
|
|
||||||
linux_first = 0;
|
|
||||||
}
|
|
||||||
s->vaddr = (char *) strtoul(pbuffer,NULL,16);
|
|
||||||
s->size = strtoul(pbuffer+9,NULL,16) - (long) (s->vaddr);
|
|
||||||
s->offset = strtoul(pbuffer+23,NULL,16);
|
|
||||||
if (strcmp(linux_firstsegment, s->mappath) == 0) {
|
|
||||||
s->base = 0;
|
|
||||||
} else {
|
|
||||||
s->base = s->vaddr;
|
|
||||||
}
|
|
||||||
s++;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* segment_solaris.c
|
|
||||||
*
|
|
||||||
* This file reads the virtual memory map on Solaris machines.
|
|
||||||
* This file is not compiled directly, it is included in the
|
|
||||||
* segment.c file.
|
|
||||||
*
|
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
|
||||||
*
|
|
||||||
* Copyright (C) 2000. The University of Chicago
|
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
segment_open() {
|
|
||||||
int f;
|
|
||||||
f = open("/proc/self/map", O_RDONLY);
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
segment_read(int fs, WadSegment *s) {
|
|
||||||
int dz;
|
|
||||||
int n;
|
|
||||||
prmap_t pmap;
|
|
||||||
|
|
||||||
n = read(fs, &pmap, sizeof(prmap_t));
|
|
||||||
if (n <= 0) return 0;
|
|
||||||
s->mapname = wad_strdup(pmap.pr_mapname);
|
|
||||||
s->mappath = (char *) wad_malloc(20+strlen(pmap.pr_mapname));
|
|
||||||
strcpy(s->mappath,"/proc/self/object/");
|
|
||||||
strcat(s->mappath,pmap.pr_mapname);
|
|
||||||
s->vaddr = (char *) pmap.pr_vaddr;
|
|
||||||
|
|
||||||
/* This is a solaris oddity. a.out section starts 1 page up, but
|
|
||||||
symbols are relative to a base of 0 */
|
|
||||||
|
|
||||||
if (strcmp(s->mapname,"a.out") == 0) s->base = 0;
|
|
||||||
else s->base = s->vaddr;
|
|
||||||
|
|
||||||
s->size = pmap.pr_size;
|
|
||||||
s->offset = pmap.pr_offset;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
@ -5,8 +5,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -20,7 +33,7 @@ static int num_return = 0;
|
||||||
void wad_set_return(const char *name, long value) {
|
void wad_set_return(const char *name, long value) {
|
||||||
WadReturnFunc *rp;
|
WadReturnFunc *rp;
|
||||||
rp = &return_points[num_return];
|
rp = &return_points[num_return];
|
||||||
strcpy(rp->name,name);
|
wad_strcpy(rp->name,name);
|
||||||
rp->value = value;
|
rp->value = value;
|
||||||
num_return++;
|
num_return++;
|
||||||
if (wad_debug_mode & DEBUG_RETURN) {
|
if (wad_debug_mode & DEBUG_RETURN) {
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -20,12 +33,105 @@
|
||||||
/* Include the proper code for reading the segment map */
|
/* Include the proper code for reading the segment map */
|
||||||
|
|
||||||
#ifdef WAD_SOLARIS
|
#ifdef WAD_SOLARIS
|
||||||
#include "plat/segment_solaris.c"
|
|
||||||
#endif
|
/* This code is used to read the process virtual memory map on Solaris machines */
|
||||||
|
|
||||||
|
static int
|
||||||
|
segment_open() {
|
||||||
|
int f;
|
||||||
|
f = open("/proc/self/map", O_RDONLY);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
segment_read(int fs, WadSegment *s) {
|
||||||
|
int dz;
|
||||||
|
int n;
|
||||||
|
prmap_t pmap;
|
||||||
|
|
||||||
|
n = read(fs, &pmap, sizeof(prmap_t));
|
||||||
|
if (n <= 0) return 0;
|
||||||
|
s->mapname = wad_strdup(pmap.pr_mapname);
|
||||||
|
s->mappath = (char *) wad_malloc(20+strlen(pmap.pr_mapname));
|
||||||
|
wad_strcpy(s->mappath,"/proc/self/object/");
|
||||||
|
strcat(s->mappath,pmap.pr_mapname);
|
||||||
|
s->vaddr = (char *) pmap.pr_vaddr;
|
||||||
|
|
||||||
|
/* This is a solaris oddity. a.out section starts 1 page up, but
|
||||||
|
symbols are relative to a base of 0 */
|
||||||
|
|
||||||
|
if (strcmp(s->mapname,"a.out") == 0) s->base = 0;
|
||||||
|
else s->base = s->vaddr;
|
||||||
|
|
||||||
|
s->size = pmap.pr_size;
|
||||||
|
s->offset = pmap.pr_offset;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* WAD_SOLARIS */
|
||||||
|
|
||||||
#ifdef WAD_LINUX
|
#ifdef WAD_LINUX
|
||||||
#include "plat/segment_linux.c"
|
static char linux_firstsegment[1024];
|
||||||
#endif
|
static int linux_first = 1;
|
||||||
|
|
||||||
|
static int
|
||||||
|
segment_open() {
|
||||||
|
FILE *f;
|
||||||
|
f = fopen("/proc/self/maps", "r");
|
||||||
|
linux_first =1;
|
||||||
|
return (int) f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
segment_read(int fd, WadSegment *s)
|
||||||
|
{
|
||||||
|
char pbuffer[1024];
|
||||||
|
char *c;
|
||||||
|
int len;
|
||||||
|
FILE *fs = (FILE *) fd;
|
||||||
|
c = fgets(pbuffer,1024,fs);
|
||||||
|
if (!c) return 0;
|
||||||
|
|
||||||
|
pbuffer[strlen(pbuffer)-1] = 0; /* Chop off endline */
|
||||||
|
|
||||||
|
/* Break up the field into records */
|
||||||
|
/* 0-8 : Starting address
|
||||||
|
9-17 : Ending Address
|
||||||
|
18 : r
|
||||||
|
19 : w
|
||||||
|
20 : x
|
||||||
|
21 : p
|
||||||
|
23-31 : Offset
|
||||||
|
49- : Filename */
|
||||||
|
|
||||||
|
len = strlen(pbuffer);
|
||||||
|
pbuffer[8] = 0;
|
||||||
|
pbuffer[17] = 0;
|
||||||
|
pbuffer[31] = 0;
|
||||||
|
if (len >= 49) {
|
||||||
|
s->mapname = wad_strdup(pbuffer+49);
|
||||||
|
s->mappath = s->mapname;
|
||||||
|
} else {
|
||||||
|
s->mapname = "";
|
||||||
|
s->mappath = s->mapname;
|
||||||
|
}
|
||||||
|
if (linux_first) {
|
||||||
|
wad_strcpy(linux_firstsegment, s->mappath);
|
||||||
|
linux_first = 0;
|
||||||
|
}
|
||||||
|
s->vaddr = (char *) strtoul(pbuffer,NULL,16);
|
||||||
|
s->size = strtoul(pbuffer+9,NULL,16) - (long) (s->vaddr);
|
||||||
|
s->offset = strtoul(pbuffer+23,NULL,16);
|
||||||
|
if (strcmp(linux_firstsegment, s->mappath) == 0) {
|
||||||
|
s->base = 0;
|
||||||
|
} else {
|
||||||
|
s->base = s->vaddr;
|
||||||
|
}
|
||||||
|
s++;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* WAD_LINUX */
|
||||||
|
|
||||||
static WadSegment *segments = 0; /* Linked list of segments */
|
static WadSegment *segments = 0; /* Linked list of segments */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -309,20 +322,17 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) {
|
||||||
p_sp = (unsigned long) (*sp);
|
p_sp = (unsigned long) (*sp);
|
||||||
#ifdef WAD_LINUX
|
#ifdef WAD_LINUX
|
||||||
p_fp = (unsigned long) (*fp);
|
p_fp = (unsigned long) (*fp);
|
||||||
/* printf("fault at address %x, pc = %x, sp = %x, fp = %x\n", addr, p_pc, p_sp, p_fp); */
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef WAD_SOLARIS
|
#ifdef WAD_SOLARIS
|
||||||
p_fp = (unsigned long) *(((long *) p_sp) + 14);
|
p_fp = (unsigned long) *(((long *) p_sp) + 14);
|
||||||
#endif
|
#endif
|
||||||
/* printf("fault at address %x, pc = %x, sp = %x, fp = %x\n", addr, p_pc, p_sp, p_fp);*/
|
|
||||||
|
|
||||||
|
|
||||||
if (wad_debug_mode & DEBUG_SIGNAL) {
|
if (wad_debug_mode & DEBUG_SIGNAL) {
|
||||||
printf("fault at address %x, pc = %x, sp = %x, fp = %x\n", addr, p_pc, p_sp, p_fp);
|
wad_printf("fault at address %x, pc = %x, sp = %x, fp = %x\n", addr, p_pc, p_sp, p_fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wad_stacked_signal) {
|
if (wad_stacked_signal) {
|
||||||
printf("Fault in wad at pc = %x, sp = %x\n", p_pc, p_sp);
|
wad_printf("Fault in wad at pc = %x, sp = %x\n", p_pc, p_sp);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
wad_stacked_signal++;
|
wad_stacked_signal++;
|
||||||
|
|
@ -330,11 +340,10 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) {
|
||||||
|
|
||||||
if (!frame) {
|
if (!frame) {
|
||||||
/* We're really hosed. Not possible to generate a stack trace */
|
/* We're really hosed. Not possible to generate a stack trace */
|
||||||
printf("WAD: Unable to generate stack trace.\n");
|
wad_printf("WAD: Unable to generate stack trace.\n");
|
||||||
printf("WAD: Maybe the call stack has been corrupted by buffer overflow.\n");
|
wad_printf("WAD: Maybe the call stack has been corrupted by buffer overflow.\n");
|
||||||
wad_signal_clear();
|
wad_signal_clear();
|
||||||
return;
|
return;
|
||||||
/* exit(1); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -342,12 +351,15 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) {
|
||||||
while (f) {
|
while (f) {
|
||||||
wad_find_object(f);
|
wad_find_object(f);
|
||||||
wad_find_symbol(f);
|
wad_find_symbol(f);
|
||||||
|
f = f->next;
|
||||||
|
}
|
||||||
|
f = frame;
|
||||||
|
while (f) {
|
||||||
wad_find_debug(f);
|
wad_find_debug(f);
|
||||||
wad_build_vars(f);
|
wad_build_vars(f);
|
||||||
f = f->next;
|
f = f->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wad_heap_overflow = 0;
|
wad_heap_overflow = 0;
|
||||||
if (sig == SIGSEGV) {
|
if (sig == SIGSEGV) {
|
||||||
if (addr >= current_brk) wad_heap_overflow = 1;
|
if (addr >= current_brk) wad_heap_overflow = 1;
|
||||||
|
|
@ -428,10 +440,10 @@ void wad_signal_init() {
|
||||||
static stack_t sigstk;
|
static stack_t sigstk;
|
||||||
|
|
||||||
if (wad_debug_mode & DEBUG_INIT) {
|
if (wad_debug_mode & DEBUG_INIT) {
|
||||||
printf("WAD: Initializing signal handler.\n");
|
wad_printf("WAD: Initializing signal handler.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is buggy in Linux and threads. disabled by default */
|
/* This is buggy in Linux and threads. disabled by default */
|
||||||
|
|
||||||
#ifndef WAD_LINUX
|
#ifndef WAD_LINUX
|
||||||
/* Set up an alternative stack */
|
/* Set up an alternative stack */
|
||||||
|
|
||||||
|
|
@ -470,7 +482,7 @@ void wad_signal_init() {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
werror:
|
werror:
|
||||||
printf("WAD: Couldn't install signal handler!\n");
|
wad_printf("WAD: Couldn't install signal handler!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -484,3 +496,6 @@ void wad_signal_clear() {
|
||||||
signal(SIGFPE, SIG_DFL);
|
signal(SIGFPE, SIG_DFL);
|
||||||
signal(SIGABRT, SIG_DFL);
|
signal(SIGABRT, SIG_DFL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -147,7 +160,6 @@ static void type_add(char *name, char *value) {
|
||||||
add_more:
|
add_more:
|
||||||
if (vr) {
|
if (vr) {
|
||||||
/* There is a mapping to another type */
|
/* There is a mapping to another type */
|
||||||
/* printf("adding '%s', '%s'\n", v, vr); */
|
|
||||||
type_add(v,vr);
|
type_add(v,vr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -274,7 +286,7 @@ static void types_print() {
|
||||||
for (i = 0; i < HASH_SIZE; i++) {
|
for (i = 0; i < HASH_SIZE; i++) {
|
||||||
s = lnames[i];
|
s = lnames[i];
|
||||||
while (s) {
|
while (s) {
|
||||||
printf("%20s %s\n", s->name, s->value);
|
wad_printf("%20s %s\n", s->name, s->value);
|
||||||
s = s->next;
|
s = s->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -318,7 +330,6 @@ stab_symbol(Stab *s, char *stabstr) {
|
||||||
char *pstr;
|
char *pstr;
|
||||||
char name[1024];
|
char name[1024];
|
||||||
char value[65536];
|
char value[65536];
|
||||||
int a;
|
|
||||||
|
|
||||||
str = stabstr+s->n_strx;
|
str = stabstr+s->n_strx;
|
||||||
pstr = stab_string_parm(str);
|
pstr = stab_string_parm(str);
|
||||||
|
|
@ -331,7 +342,7 @@ stab_symbol(Stab *s, char *stabstr) {
|
||||||
/* printf("stab lsym: other=%d, desc=%d, value=%d, str='%s'\n", s->n_other,s->n_desc,s->n_value,
|
/* printf("stab lsym: other=%d, desc=%d, value=%d, str='%s'\n", s->n_other,s->n_desc,s->n_value,
|
||||||
stabstr+s->n_strx); */
|
stabstr+s->n_strx); */
|
||||||
/* wad_printf("name = '%s', pstr='%s'\n", name, pstr+2); */
|
/* wad_printf("name = '%s', pstr='%s'\n", name, pstr+2); */
|
||||||
strcpy(value,pstr+2);
|
wad_strcpy(value,pstr+2);
|
||||||
type_add(name,value);
|
type_add(name,value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -343,7 +354,7 @@ stab_symbol(Stab *s, char *stabstr) {
|
||||||
* Collect stabs data for a function definition.
|
* Collect stabs data for a function definition.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static int
|
||||||
scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
|
scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
|
||||||
int i;
|
int i;
|
||||||
unsigned long offset;
|
unsigned long offset;
|
||||||
|
|
@ -362,7 +373,7 @@ scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((s->n_type == N_UNDF) || (s->n_type == N_SO) || (s->n_type == N_FUN) ||
|
if ((s->n_type == N_UNDF) || (s->n_type == N_SO) || (s->n_type == N_FUN) ||
|
||||||
(s->n_type == N_OBJ)) return;
|
(s->n_type == N_OBJ)) return i;
|
||||||
|
|
||||||
if (s->n_type == N_LBRAC) {
|
if (s->n_type == N_LBRAC) {
|
||||||
get_parms = 0;
|
get_parms = 0;
|
||||||
|
|
@ -372,7 +383,7 @@ scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
|
||||||
|
|
||||||
if (s->n_type == N_LSYM) {
|
if (s->n_type == N_LSYM) {
|
||||||
/* This might be a local variable definition */
|
/* This might be a local variable definition */
|
||||||
/* printf("local: n_value = %d, offset = %d\n", s->n_value, offset);*/
|
/* wad_printf("local: n_value = %d, offset = %d\n", s->n_value, offset);*/
|
||||||
if (s->n_desc <= f->loc_line)
|
if (s->n_desc <= f->loc_line)
|
||||||
{
|
{
|
||||||
/* Okay. We can pay attention to it */
|
/* Okay. We can pay attention to it */
|
||||||
|
|
@ -426,7 +437,7 @@ scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
|
||||||
t = type_resolve(tname);
|
t = type_resolve(tname);
|
||||||
arg->type = type_typecode(t);
|
arg->type = type_typecode(t);
|
||||||
if (wad_debug_mode & DEBUG_STABS) {
|
if (wad_debug_mode & DEBUG_STABS) {
|
||||||
printf("type_resolve '%s' -> '%s' (%d)\n", tname, t, arg->type);
|
wad_printf("type_resolve '%s' -> '%s' (%d)\n", tname, t, arg->type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (f->debug_locals) {
|
if (f->debug_locals) {
|
||||||
|
|
@ -523,7 +534,7 @@ scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
|
||||||
t = type_resolve(tname);
|
t = type_resolve(tname);
|
||||||
arg->type = type_typecode(t);
|
arg->type = type_typecode(t);
|
||||||
if (wad_debug_mode & DEBUG_STABS) {
|
if (wad_debug_mode & DEBUG_STABS) {
|
||||||
printf("type_resolve '%s' -> '%s' (%d)\n", tname, t, arg->type);
|
wad_printf("type_resolve '%s' -> '%s' (%d)\n", tname, t, arg->type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (f->debug_args) {
|
if (f->debug_args) {
|
||||||
|
|
@ -537,6 +548,7 @@ scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
|
||||||
f->debug_nargs++;
|
f->debug_nargs++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Given a stabs data segment (obtained somehow), this function tries to
|
/* Given a stabs data segment (obtained somehow), this function tries to
|
||||||
|
|
@ -557,19 +569,15 @@ int
|
||||||
wad_search_stab(void *sp, int size, char *stabstr, WadFrame *f) {
|
wad_search_stab(void *sp, int size, char *stabstr, WadFrame *f) {
|
||||||
Stab *s;
|
Stab *s;
|
||||||
int ns;
|
int ns;
|
||||||
int infunc;
|
|
||||||
int slen;
|
|
||||||
int i;
|
int i;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
int filefound = 0;
|
|
||||||
|
|
||||||
char *file, *lastfile = 0;
|
char *file, *lastfile = 0;
|
||||||
int chk = 0;
|
|
||||||
WadLocal *arg;
|
|
||||||
|
|
||||||
char srcfile[MAX_PATH];
|
char srcfile[MAX_PATH];
|
||||||
char objfile[MAX_PATH];
|
char objfile[MAX_PATH];
|
||||||
|
|
||||||
|
|
||||||
/* It appears to be necessary to clear the types table on each new stabs section */
|
/* It appears to be necessary to clear the types table on each new stabs section */
|
||||||
|
|
||||||
init_hash();
|
init_hash();
|
||||||
|
|
@ -579,7 +587,6 @@ wad_search_stab(void *sp, int size, char *stabstr, WadFrame *f) {
|
||||||
s = (Stab *) sp; /* Stabs data */
|
s = (Stab *) sp; /* Stabs data */
|
||||||
ns = size/sizeof(Stab); /* number of stabs */
|
ns = size/sizeof(Stab); /* number of stabs */
|
||||||
|
|
||||||
slen = strlen(f->sym_name);
|
|
||||||
srcfile[0] = 0;
|
srcfile[0] = 0;
|
||||||
objfile[0] = 0;
|
objfile[0] = 0;
|
||||||
|
|
||||||
|
|
@ -597,7 +604,8 @@ wad_search_stab(void *sp, int size, char *stabstr, WadFrame *f) {
|
||||||
/* New stabs section. We need to be a little careful here. Do a recursive
|
/* New stabs section. We need to be a little careful here. Do a recursive
|
||||||
search of the subsection. */
|
search of the subsection. */
|
||||||
|
|
||||||
if (wad_search_stab(s+1,s->n_desc*sizeof(Stab), stabstr, f)) return 1;
|
/* if (wad_search_stab(s+1,s->n_desc*sizeof(Stab), stabstr, f)) return 1; */
|
||||||
|
wad_search_stab(s+1,s->n_desc*sizeof(Stab), stabstr, f);
|
||||||
|
|
||||||
/* On solaris, each stabs section seems to increment the stab string pointer. On Linux,
|
/* On solaris, each stabs section seems to increment the stab string pointer. On Linux,
|
||||||
the linker seems to do a certain amount of optimization that results in a single
|
the linker seems to do a certain amount of optimization that results in a single
|
||||||
|
|
@ -616,9 +624,9 @@ wad_search_stab(void *sp, int size, char *stabstr, WadFrame *f) {
|
||||||
/* Look for directory */
|
/* Look for directory */
|
||||||
file = stabstr+s->n_strx;
|
file = stabstr+s->n_strx;
|
||||||
if (strlen(file) && (file[strlen(file)-1] == '/')) {
|
if (strlen(file) && (file[strlen(file)-1] == '/')) {
|
||||||
strcpy(srcfile,file);
|
wad_strcpy(srcfile,file);
|
||||||
} else {
|
} else {
|
||||||
strcat(srcfile,file);
|
wad_strcat(srcfile,file);
|
||||||
}
|
}
|
||||||
objfile[0] = 0;
|
objfile[0] = 0;
|
||||||
/* If we have a file match, we might be looking for a local symbol. If so,
|
/* If we have a file match, we might be looking for a local symbol. If so,
|
||||||
|
|
@ -626,37 +634,54 @@ wad_search_stab(void *sp, int size, char *stabstr, WadFrame *f) {
|
||||||
|
|
||||||
/* We're going to check for a file match. Maybe we're looking for a local symbol */
|
/* We're going to check for a file match. Maybe we're looking for a local symbol */
|
||||||
if (f->sym_file && strcmp(f->sym_file,file) == 0) {
|
if (f->sym_file && strcmp(f->sym_file,file) == 0) {
|
||||||
filefound = 1;
|
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
lastfile = file;
|
lastfile = file;
|
||||||
} else if (s->n_type == N_OBJ) {
|
} else if (s->n_type == N_OBJ) {
|
||||||
/* Object file specifier */
|
/* Object file specifier */
|
||||||
if (objfile[0]) {
|
if (objfile[0]) {
|
||||||
strcat(objfile,"/");
|
wad_strcat(objfile,"/");
|
||||||
}
|
}
|
||||||
strcat(objfile,stabstr+s->n_strx);
|
wad_strcat(objfile,stabstr+s->n_strx);
|
||||||
} else if (s->n_type == N_FUN) {
|
} else if (s->n_type == N_FUN) {
|
||||||
if (match_stab_symbol(f->sym_name, stabstr+s->n_strx, slen)) {
|
|
||||||
if (!f->sym_file || (strcmp(f->sym_file,lastfile) == 0)) {
|
/* Due to the bogosity and performance issues of managing stabs types, we are going to check
|
||||||
|
the current frame as well as all remaining unchecked stack frames for a match. Generally,
|
||||||
|
it is much faster for us to scan the stabs data once checking N stack frames than it
|
||||||
|
is to check N stack frames, scanning the stabs data each time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
WadFrame *g;
|
||||||
|
g = f;
|
||||||
|
while (g) {
|
||||||
|
if ((!g->sym_name) || (g->debug_check)) {
|
||||||
|
g = g->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (match_stab_symbol(g->sym_name, stabstr+s->n_strx, g->sym_nlen)) {
|
||||||
|
if (!g->sym_file || (strcmp(g->sym_file,lastfile) == 0)) {
|
||||||
|
int n;
|
||||||
/* Go find debugging information for the function */
|
/* Go find debugging information for the function */
|
||||||
scan_function(s+1, stabstr, ns -i - 1, f);
|
n = scan_function(s+1, stabstr, ns -i - 1, g);
|
||||||
|
g->loc_srcfile = wad_string_lookup(srcfile);
|
||||||
|
g->loc_objfile = wad_string_lookup(objfile);
|
||||||
|
g->debug_check = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g = g->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* If found, but no other debugging information was filled in, go ahead and copy the
|
||||||
|
source and objfile information */
|
||||||
|
|
||||||
|
if ((found) && (!f->debug_check)) {
|
||||||
f->loc_srcfile = wad_string_lookup(srcfile);
|
f->loc_srcfile = wad_string_lookup(srcfile);
|
||||||
f->loc_objfile = wad_string_lookup(objfile);
|
f->loc_objfile = wad_string_lookup(objfile);
|
||||||
/* f->loc_srcfile = wad_strdup(srcfile);
|
|
||||||
f->loc_objfile = wad_strdup(objfile); */
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found) {
|
|
||||||
f->loc_srcfile = wad_string_lookup(srcfile);
|
|
||||||
f->loc_objfile = wad_string_lookup(objfile);
|
|
||||||
/* f->loc_srcfile = wad_strdup(srcfile);
|
|
||||||
f->loc_objfile = wad_strdup(objfile); */
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -31,6 +44,7 @@ new_frame() {
|
||||||
f->stack_size = 0;
|
f->stack_size = 0;
|
||||||
|
|
||||||
f->sym_name = 0;
|
f->sym_name = 0;
|
||||||
|
f->sym_nlen = 0;
|
||||||
f->sym_file = 0;
|
f->sym_file = 0;
|
||||||
f->sym_base = 0;
|
f->sym_base = 0;
|
||||||
f->sym_size = 0;
|
f->sym_size = 0;
|
||||||
|
|
@ -41,6 +55,7 @@ new_frame() {
|
||||||
f->loc_srcfile = 0;
|
f->loc_srcfile = 0;
|
||||||
f->loc_line = 0;
|
f->loc_line = 0;
|
||||||
|
|
||||||
|
f->debug_check = 0;
|
||||||
f->debug_nargs = -1;
|
f->debug_nargs = -1;
|
||||||
f->debug_args = 0;
|
f->debug_args = 0;
|
||||||
f->debug_lastarg = 0;
|
f->debug_lastarg = 0;
|
||||||
|
|
@ -111,7 +126,7 @@ stack_unwind(unsigned long *pc, unsigned long *sp, unsigned long *fp) {
|
||||||
f->stack_size = fake_fp - *sp;
|
f->stack_size = fake_fp - *sp;
|
||||||
/* Make a copy of the call stack */
|
/* Make a copy of the call stack */
|
||||||
f->stack = (char *) wad_malloc(f->stack_size);
|
f->stack = (char *) wad_malloc(f->stack_size);
|
||||||
memcpy(f->stack,(void *) *sp, f->stack_size);
|
wad_memcpy(f->stack,(void *) *sp, f->stack_size);
|
||||||
|
|
||||||
/* Update the sp, fp, and pc */
|
/* Update the sp, fp, and pc */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -90,4 +103,26 @@ void wad_string_debug() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Our own string copy */
|
||||||
|
char *wad_strcpy(char *t, const char *s) {
|
||||||
|
if (s)
|
||||||
|
for (; *s; s++, t++) *t = *s;
|
||||||
|
*t = 0;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
wad_strcat(char *t, const char *s) {
|
||||||
|
while (*t) t++;
|
||||||
|
return wad_strcpy(t,s);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
wad_strlen(const char *s) {
|
||||||
|
int count = 0;
|
||||||
|
while (*(s++)) count++;
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,21 @@
|
||||||
*
|
*
|
||||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2000. The University of Chicago
|
* Copyright (C) 2001
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
*
|
||||||
|
* 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 "wad.h"
|
#include "wad.h"
|
||||||
|
|
@ -27,8 +40,6 @@ void wad_build_vars(WadFrame *f) {
|
||||||
char *nstack = 0;
|
char *nstack = 0;
|
||||||
char *pstack = 0;
|
char *pstack = 0;
|
||||||
WadLocal *loc;
|
WadLocal *loc;
|
||||||
int laststack = 0;
|
|
||||||
WadLocal *lastloc = 0;
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
stack = (char *) f->stack;
|
stack = (char *) f->stack;
|
||||||
|
|
@ -99,9 +110,9 @@ char *wad_format_int(char *ptr, int nbytes, int sgn) {
|
||||||
value = (value << 8) + *s;
|
value = (value << 8) + *s;
|
||||||
}
|
}
|
||||||
if (sgn) {
|
if (sgn) {
|
||||||
sprintf(fmt,"%ld", (long) value);
|
return wad_format_signed((long) value,-1);
|
||||||
} else {
|
} else {
|
||||||
sprintf(fmt,"%lu", value);
|
return wad_format_unsigned((unsigned long) value, -1);
|
||||||
}
|
}
|
||||||
return fmt;
|
return fmt;
|
||||||
}
|
}
|
||||||
|
|
@ -117,32 +128,35 @@ char *wad_format_var(WadLocal *l) {
|
||||||
|
|
||||||
switch(l->type) {
|
switch(l->type) {
|
||||||
case WAD_TYPE_INT32:
|
case WAD_TYPE_INT32:
|
||||||
strcpy(buffer,wad_format_int(l->ptr,4,1));
|
wad_strcpy(buffer,wad_format_int(l->ptr,4,1));
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_UINT32:
|
case WAD_TYPE_UINT32:
|
||||||
strcpy(buffer,wad_format_int(l->ptr,4,0));
|
wad_strcpy(buffer,wad_format_int(l->ptr,4,0));
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_INT16:
|
case WAD_TYPE_INT16:
|
||||||
strcpy(buffer,wad_format_int(l->ptr,2,1));
|
wad_strcpy(buffer,wad_format_int(l->ptr,2,1));
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_UINT16:
|
case WAD_TYPE_UINT16:
|
||||||
strcpy(buffer,wad_format_int(l->ptr,2,0));
|
wad_strcpy(buffer,wad_format_int(l->ptr,2,0));
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_INT8:
|
case WAD_TYPE_INT8:
|
||||||
strcpy(buffer,wad_format_int(l->ptr,1,1));
|
wad_strcpy(buffer,wad_format_int(l->ptr,1,1));
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_UINT8:
|
case WAD_TYPE_UINT8:
|
||||||
strcpy(buffer,wad_format_int(l->ptr,1,0));
|
wad_strcpy(buffer,wad_format_int(l->ptr,1,0));
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_CHAR:
|
case WAD_TYPE_CHAR:
|
||||||
sprintf(buffer,"'%c'", *((char *)l->ptr));
|
buffer[0] = '\'';
|
||||||
|
buffer[1] = *((char *) l->ptr);
|
||||||
|
buffer[2] = '\'';
|
||||||
|
buffer[3] = 0;
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_FLOAT:
|
case WAD_TYPE_FLOAT:
|
||||||
memcpy(&fval,l->ptr,sizeof(float));
|
wad_memcpy(&fval,l->ptr,sizeof(float));
|
||||||
sprintf(buffer,"%g",fval);
|
sprintf(buffer,"%g",fval);
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_DOUBLE:
|
case WAD_TYPE_DOUBLE:
|
||||||
memcpy(&dval,l->ptr,sizeof(double));
|
wad_memcpy(&dval,l->ptr,sizeof(double));
|
||||||
sprintf(buffer,"%g",dval);
|
sprintf(buffer,"%g",dval);
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_UNKNOWN:
|
case WAD_TYPE_UNKNOWN:
|
||||||
|
|
@ -155,6 +169,7 @@ char *wad_format_var(WadLocal *l) {
|
||||||
int leading = 1;
|
int leading = 1;
|
||||||
char *c;
|
char *c;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
#ifdef WAD_LITTLE_ENDIAN
|
#ifdef WAD_LITTLE_ENDIAN
|
||||||
ptr = ((char *) l->ptr) + 3;
|
ptr = ((char *) l->ptr) + 3;
|
||||||
incr = -1;
|
incr = -1;
|
||||||
|
|
@ -162,9 +177,9 @@ char *wad_format_var(WadLocal *l) {
|
||||||
ptr = (char *) l->ptr;
|
ptr = (char *) l->ptr;
|
||||||
incr =1 ;
|
incr =1 ;
|
||||||
#endif
|
#endif
|
||||||
strcat(buffer,"0x");
|
wad_strcat(buffer,"0x");
|
||||||
c = buffer+2;
|
c = buffer+2;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < sizeof(void *); i++) {
|
||||||
b = (int) *ptr;
|
b = (int) *ptr;
|
||||||
if (!leading || (b)) {
|
if (!leading || (b)) {
|
||||||
if (!leading || (b & 0xf0))
|
if (!leading || (b & 0xf0))
|
||||||
|
|
@ -195,39 +210,37 @@ long wad_local_as_long(WadLocal *loc) {
|
||||||
|
|
||||||
switch(loc->type) {
|
switch(loc->type) {
|
||||||
case WAD_TYPE_INT32:
|
case WAD_TYPE_INT32:
|
||||||
memcpy(&i32,loc->ptr,4);
|
wad_memcpy(&i32,loc->ptr,4);
|
||||||
value = (long) i32;
|
value = (long) i32;
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_UINT32:
|
case WAD_TYPE_UINT32:
|
||||||
memcpy(&u32,loc->ptr,4);
|
wad_memcpy(&u32,loc->ptr,4);
|
||||||
value = (long) u32;
|
value = (long) u32;
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_INT16:
|
case WAD_TYPE_INT16:
|
||||||
memcpy(&i16,loc->ptr,2);
|
wad_memcpy(&i16,loc->ptr,2);
|
||||||
value = (long) i16;
|
value = (long) i16;
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_UINT16:
|
case WAD_TYPE_UINT16:
|
||||||
memcpy(&u16,loc->ptr,2);
|
wad_memcpy(&u16,loc->ptr,2);
|
||||||
value = (long) u16;
|
value = (long) u16;
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_INT8:
|
case WAD_TYPE_INT8:
|
||||||
case WAD_TYPE_CHAR:
|
case WAD_TYPE_CHAR:
|
||||||
memcpy(&i8, loc->ptr,1);
|
wad_memcpy(&i8, loc->ptr,1);
|
||||||
value = (long) i8;
|
value = (long) i8;
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_UINT8:
|
case WAD_TYPE_UINT8:
|
||||||
memcpy(&u8, loc->ptr,1);
|
wad_memcpy(&u8, loc->ptr,1);
|
||||||
value = (long) u8;
|
value = (long) u8;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
memcpy(&u32,loc->ptr,4);
|
wad_memcpy(&u32,loc->ptr,4);
|
||||||
value = (long) u32;
|
value = (long) u32;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Convert a wad local variable to a long */
|
/* Convert a wad local variable to a long */
|
||||||
double wad_local_as_double(WadLocal *loc) {
|
double wad_local_as_double(WadLocal *loc) {
|
||||||
double value = 0;
|
double value = 0;
|
||||||
|
|
@ -235,10 +248,10 @@ double wad_local_as_double(WadLocal *loc) {
|
||||||
|
|
||||||
switch(loc->type) {
|
switch(loc->type) {
|
||||||
case WAD_TYPE_DOUBLE:
|
case WAD_TYPE_DOUBLE:
|
||||||
memcpy(&value,loc->ptr,8);
|
wad_memcpy(&value,loc->ptr,8);
|
||||||
break;
|
break;
|
||||||
case WAD_TYPE_FLOAT:
|
case WAD_TYPE_FLOAT:
|
||||||
memcpy(&fval,loc->ptr,4);
|
wad_memcpy(&fval,loc->ptr,4);
|
||||||
value = (double) fval;
|
value = (double) fval;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue