From 03e3937ec7d1b356039433137cc6e531379ca454 Mon Sep 17 00:00:00 2001 From: Dave Anderson Date: Tue, 28 Jan 2014 16:46:11 -0500 Subject: [PATCH] Initial commit: crash-7.0.4 --- .gitignore | 13 + .rh_rpm_package | 1 + COPYING3 | 674 ++ Makefile | 604 ++ README | 355 + alpha.c | 2733 ++++++ arm.c | 1631 ++++ arm64.c | 1351 +++ cmdline.c | 2508 ++++++ configure.c | 1686 ++++ crash.8 | 830 ++ defs.h | 5964 +++++++++++++ dev.c | 4076 +++++++++ diskdump.c | 2060 +++++ diskdump.h | 99 + extensions.c | 559 ++ extensions/Makefile | 54 + extensions/dminfo.c | 1533 ++++ extensions/echo.c | 110 + extensions/eppic.c | 4 + extensions/eppic.mk | 72 + extensions/snap.c | 752 ++ extensions/snap.mk | 46 + extensions/trace.c | 2205 +++++ filesys.c | 4082 +++++++++ gdb-7.6.patch | 1563 ++++ gdb_interface.c | 1027 +++ global_data.c | 138 + help.c | 8093 +++++++++++++++++ ia64.c | 4450 ++++++++++ ibm_common.h | 102 + ipcs.c | 1085 +++ kernel.c | 9223 ++++++++++++++++++++ kvmdump.c | 1263 +++ kvmdump.h | 109 + lkcd_common.c | 1437 +++ lkcd_dump_v5.h | 256 + lkcd_dump_v7.h | 416 + lkcd_dump_v8.h | 538 ++ lkcd_fix_mem.c | 110 + lkcd_fix_mem.h | 309 + lkcd_v1.c | 305 + lkcd_v2_v3.c | 482 ++ lkcd_v5.c | 422 + lkcd_v7.c | 500 ++ lkcd_v8.c | 700 ++ lkcd_vmdump_v1.h | 160 + lkcd_vmdump_v2_v3.h | 244 + lkcd_x86_trace.c | 6122 +++++++++++++ lkcd_x86_trace.h | 785 ++ main.c | 1792 ++++ makedumpfile.c | 328 + makedumpfile.h | 46 + memory.c | 17782 ++++++++++++++++++++++++++++++++++++++ memory_driver/Makefile | 15 + memory_driver/README | 24 + memory_driver/crash.c | 180 + net.c | 1628 ++++ netdump.c | 4070 +++++++++ netdump.h | 203 + ppc.c | 2050 +++++ ppc64.c | 2967 +++++++ qemu-load.c | 1102 +++ qemu-load.h | 223 + qemu.c | 334 + remote.c | 3888 +++++++++ rse.h | 89 + s390.c | 1150 +++ s390_dump.c | 110 + s390dbf.c | 1454 ++++ s390x.c | 1636 ++++ sadump.c | 1619 ++++ sadump.h | 218 + symbols.c | 11821 +++++++++++++++++++++++++ task.c | 9258 ++++++++++++++++++++ test.c | 99 + tools.c | 5754 ++++++++++++ unwind.c | 3129 +++++++ unwind.h | 675 ++ unwind_arm.c | 755 ++ unwind_decoder.c | 487 ++ unwind_i.h | 196 + unwind_x86.h | 12 + unwind_x86_32_64.c | 1251 +++ unwind_x86_64.h | 106 + va_server.c | 444 + va_server.h | 67 + va_server_v1.c | 366 + vas_crash.h | 108 + x86.c | 5650 ++++++++++++ x86_64.c | 7709 +++++++++++++++++ xen_hyper.c | 2120 +++++ xen_hyper_command.c | 1867 ++++ xen_hyper_defs.h | 988 +++ xen_hyper_dump_tables.c | 951 ++ xen_hyper_global_data.c | 400 + xendump.c | 2859 ++++++ xendump.h | 194 + 98 files changed, 174015 insertions(+) create mode 100644 .gitignore create mode 100644 .rh_rpm_package create mode 100644 COPYING3 create mode 100644 Makefile create mode 100644 README create mode 100644 alpha.c create mode 100644 arm.c create mode 100644 arm64.c create mode 100644 cmdline.c create mode 100644 configure.c create mode 100644 crash.8 create mode 100644 defs.h create mode 100644 dev.c create mode 100644 diskdump.c create mode 100644 diskdump.h create mode 100644 extensions.c create mode 100644 extensions/Makefile create mode 100644 extensions/dminfo.c create mode 100644 extensions/echo.c create mode 100644 extensions/eppic.c create mode 100644 extensions/eppic.mk create mode 100644 extensions/snap.c create mode 100644 extensions/snap.mk create mode 100644 extensions/trace.c create mode 100644 filesys.c create mode 100644 gdb-7.6.patch create mode 100644 gdb_interface.c create mode 100644 global_data.c create mode 100644 help.c create mode 100644 ia64.c create mode 100644 ibm_common.h create mode 100644 ipcs.c create mode 100644 kernel.c create mode 100644 kvmdump.c create mode 100644 kvmdump.h create mode 100644 lkcd_common.c create mode 100644 lkcd_dump_v5.h create mode 100644 lkcd_dump_v7.h create mode 100644 lkcd_dump_v8.h create mode 100644 lkcd_fix_mem.c create mode 100644 lkcd_fix_mem.h create mode 100644 lkcd_v1.c create mode 100644 lkcd_v2_v3.c create mode 100644 lkcd_v5.c create mode 100644 lkcd_v7.c create mode 100644 lkcd_v8.c create mode 100644 lkcd_vmdump_v1.h create mode 100644 lkcd_vmdump_v2_v3.h create mode 100644 lkcd_x86_trace.c create mode 100644 lkcd_x86_trace.h create mode 100644 main.c create mode 100644 makedumpfile.c create mode 100644 makedumpfile.h create mode 100644 memory.c create mode 100644 memory_driver/Makefile create mode 100644 memory_driver/README create mode 100644 memory_driver/crash.c create mode 100644 net.c create mode 100644 netdump.c create mode 100644 netdump.h create mode 100644 ppc.c create mode 100644 ppc64.c create mode 100644 qemu-load.c create mode 100644 qemu-load.h create mode 100644 qemu.c create mode 100644 remote.c create mode 100644 rse.h create mode 100644 s390.c create mode 100644 s390_dump.c create mode 100644 s390dbf.c create mode 100644 s390x.c create mode 100644 sadump.c create mode 100644 sadump.h create mode 100644 symbols.c create mode 100644 task.c create mode 100644 test.c create mode 100644 tools.c create mode 100644 unwind.c create mode 100644 unwind.h create mode 100644 unwind_arm.c create mode 100644 unwind_decoder.c create mode 100644 unwind_i.h create mode 100644 unwind_x86.h create mode 100644 unwind_x86_32_64.c create mode 100644 unwind_x86_64.h create mode 100644 va_server.c create mode 100644 va_server.h create mode 100644 va_server_v1.c create mode 100644 vas_crash.h create mode 100644 x86.c create mode 100644 x86_64.c create mode 100644 xen_hyper.c create mode 100644 xen_hyper_command.c create mode 100644 xen_hyper_defs.h create mode 100644 xen_hyper_dump_tables.c create mode 100644 xen_hyper_global_data.c create mode 100644 xendump.c create mode 100644 xendump.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..89cc8b66 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +configure +build_data.c +cscope.out +crashlib.a +*.o +crash +CFLAGS.extra +LDFLAGS.extra +crash.spec +*.gz +*.rpm +gdb.files +gdb-7.6/ diff --git a/.rh_rpm_package b/.rh_rpm_package new file mode 100644 index 00000000..4489f5a6 --- /dev/null +++ b/.rh_rpm_package @@ -0,0 +1 @@ +7.0.4 diff --git a/COPYING3 b/COPYING3 new file mode 100644 index 00000000..94a9ed02 --- /dev/null +++ b/COPYING3 @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. 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 +them 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 prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. 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. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey 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; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + 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. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +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. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + 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 +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 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, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program 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, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU 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 Lesser General +Public License instead of this License. But first, please read +. diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..41c0ecea --- /dev/null +++ b/Makefile @@ -0,0 +1,604 @@ +# Makefile for core analysis suite +# +# Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. +# www.missioncriticallinux.com, info@missioncriticallinux.com +# +# Copyright (C) 2002-2013 David Anderson +# Copyright (C) 2002-2013 Red Hat, Inc. 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. +# + +PROGRAM=crash + +# +# Supported targets: X86 ALPHA PPC IA64 PPC64 +# TARGET and GDB_CONF_FLAGS will be configured automatically by configure +# +TARGET= +GDB_CONF_FLAGS= + +ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/) +ifeq (${ARCH}, ppc64) +CONF_FLAGS = -m64 +endif + +# +# GDB, GDB_FILES, GDB_OFILES and GDB_PATCH_FILES will be configured automatically by configure +# +GDB= +GDB_FILES= +GDB_OFILES= +GDB_PATCH_FILES= + +# +# Default installation directory +# +INSTALLDIR=${DESTDIR}/usr/bin + +# LDFLAGS will be configured automatically by configure +LDFLAGS= + +GENERIC_HFILES=defs.h xen_hyper_defs.h +MCORE_HFILES=va_server.h vas_crash.h +REDHAT_HFILES=netdump.h diskdump.h makedumpfile.h xendump.h kvmdump.h qemu-load.h +LKCD_DUMP_HFILES=lkcd_vmdump_v1.h lkcd_vmdump_v2_v3.h lkcd_dump_v5.h \ + lkcd_dump_v7.h lkcd_dump_v8.h +LKCD_OBSOLETE_HFILES=lkcd_fix_mem.h +LKCD_TRACE_HFILES=lkcd_x86_trace.h +IBM_HFILES=ibm_common.h +SADUMP_HFILES=sadump.h +UNWIND_HFILES=unwind.h unwind_i.h rse.h unwind_x86.h unwind_x86_64.h + +CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \ + kernel.c test.c gdb_interface.c configure.c net.c dev.c \ + alpha.c x86.c ppc.c ia64.c s390.c s390x.c s390dbf.c ppc64.c x86_64.c \ + arm.c arm64.c \ + extensions.c remote.c va_server.c va_server_v1.c symbols.c cmdline.c \ + lkcd_common.c lkcd_v1.c lkcd_v2_v3.c lkcd_v5.c lkcd_v7.c lkcd_v8.c\ + lkcd_fix_mem.c s390_dump.c lkcd_x86_trace.c \ + netdump.c diskdump.c makedumpfile.c xendump.c unwind.c unwind_decoder.c \ + unwind_x86_32_64.c unwind_arm.c \ + xen_hyper.c xen_hyper_command.c xen_hyper_global_data.c \ + xen_hyper_dump_tables.c kvmdump.c qemu.c qemu-load.c sadump.c ipcs.c + +SOURCE_FILES=${CFILES} ${GENERIC_HFILES} ${MCORE_HFILES} \ + ${REDHAT_CFILES} ${REDHAT_HFILES} ${UNWIND_HFILES} \ + ${LKCD_DUMP_HFILES} ${LKCD_TRACE_HFILES} ${LKCD_OBSOLETE_HFILES}\ + ${IBM_HFILES} ${SADUMP_HFILES} + +OBJECT_FILES=main.o tools.o global_data.o memory.o filesys.o help.o task.o \ + build_data.o kernel.o test.o gdb_interface.o net.o dev.o \ + alpha.o x86.o ppc.o ia64.o s390.o s390x.o s390dbf.o ppc64.o x86_64.o \ + arm.o arm64.o \ + extensions.o remote.o va_server.o va_server_v1.o symbols.o cmdline.o \ + lkcd_common.o lkcd_v1.o lkcd_v2_v3.o lkcd_v5.o lkcd_v7.o lkcd_v8.o \ + lkcd_fix_mem.o s390_dump.o netdump.o diskdump.o makedumpfile.o xendump.o \ + lkcd_x86_trace.o unwind_v1.o unwind_v2.o unwind_v3.o \ + unwind_x86_32_64.o unwind_arm.o \ + xen_hyper.o xen_hyper_command.o xen_hyper_global_data.o \ + xen_hyper_dump_tables.o kvmdump.o qemu.o qemu-load.o sadump.o ipcs.o + +MEMORY_DRIVER_FILES=memory_driver/Makefile memory_driver/crash.c memory_driver/README + +# These are the current set of crash extensions sources. They are not built +# by default unless the third command line of the "all:" stanza is uncommented. +# Alternatively, they can be built by entering "make extensions" from this +# directory. + +EXTENSIONS=extensions +EXTENSION_SOURCE_FILES=${EXTENSIONS}/Makefile ${EXTENSIONS}/echo.c ${EXTENSIONS}/dminfo.c \ + ${EXTENSIONS}/snap.c ${EXTENSIONS}/snap.mk ${EXTENSIONS}/trace.c \ + ${EXTENSIONS}/eppic.c ${EXTENSIONS}/eppic.mk + +DAEMON_OBJECT_FILES=remote_daemon.o va_server.o va_server_v1.o \ + lkcd_common.o lkcd_v1.o lkcd_v2_v3.o lkcd_v5.o lkcd_v7.o lkcd_v8.o \ + s390_dump.o netdump_daemon.o + +GDB_5.0_FILES=${GDB}/gdb/Makefile.in \ + ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ + ${GDB}/gdb/blockframe.c ${GDB}/gdb/alpha-tdep.c \ + ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ + ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/gnu-regex.c \ + ${GDB}/gdb/ppc-linux-nat.c +GDB_5.0_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o ${GDB}/gdb/target.o \ + ${GDB}/gdb/blockframe.o ${GDB}/gdb/alpha-tdep.o \ + ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ + ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o ${GDB}/gdb/gnu-regex.o \ + ${GDB}/gdb/ppc-linux-nat.o + +GDB_5.1_FILES=${GDB}/gdb/Makefile.in \ + ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ + ${GDB}/gdb/blockframe.c ${GDB}/gdb/alpha-tdep.c \ + ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ + ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/gnu-regex.c +GDB_5.1_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o ${GDB}/gdb/target.o \ + ${GDB}/gdb/blockframe.o ${GDB}/gdb/alpha-tdep.o \ + ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ + ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o ${GDB}/gdb/gnu-regex.o + +GDB_5.2.1_FILES=${GDB}/gdb/Makefile.in \ + ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ + ${GDB}/gdb/blockframe.c ${GDB}/gdb/alpha-tdep.c \ + ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ + ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c +GDB_5.2.1_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o ${GDB}/gdb/target.o \ + ${GDB}/gdb/blockframe.o ${GDB}/gdb/alpha-tdep.o \ + ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ + ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o + +GDB_5.3post-0.20021129.36rh_FILES=${GDB}/gdb/Makefile.in \ + ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ + ${GDB}/gdb/frame.c ${GDB}/gdb/alpha-tdep.c \ + ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ + ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/dwarf2read.c +GDB_5.3post-0.20021129.36rh_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o \ + ${GDB}/gdb/target.o ${GDB}/gdb/frame.o ${GDB}/gdb/alpha-tdep.o \ + ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o ${GDB}/gdb/ui-file.o \ + ${GDB}/gdb/utils.o ${GDB}/gdb/dwarf2read.o + +GDB_6.0_FILES=${GDB}/gdb/Makefile.in ${GDB}/Makefile.in \ + ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ + ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ + ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c \ + ${GDB}/gdb/ppc-linux-tdep.c ${GDB}/sim/ppc/ppc-instructions \ + ${GDB}/bfd/simple.c ${GDB}/include/obstack.h +GDB_6.0_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o \ + ${GDB}/gdb/target.o ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ + ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o \ + ${GDB}/gdb/ppc-linux-tdep.o ${GDB}/bfd/simple.o + +GDB_6.1_FILES=${GDB}/gdb/Makefile.in ${GDB}/Makefile.in \ + ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ + ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ + ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/dwarf2read.c \ + ${GDB}/include/obstack.h ${GDB}/gdb/ppc-linux-tdep.c +GDB_6.1_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o \ + ${GDB}/gdb/target.o ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ + ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o ${GDB}/gdb/dwarf2read.o \ + ${GDB}/gdb/ppc-linux-tdep.o + +GDB_7.0_FILES= +GDB_7.0_OFILES=${GDB}/gdb/symtab.o + +GDB_7.3.1_FILES= +GDB_7.3.1_OFILES=${GDB}/gdb/symtab.o + +GDB_7.6_FILES= +GDB_7.6_OFILES=${GDB}/gdb/symtab.o + +# +# GDB_FLAGS is passed up from the gdb Makefile. +# +GDB_FLAGS= + +# +# WARNING_OPTIONS and WARNING_ERROR are both applied on a per-file basis. +# WARNING_ERROR is NOT used on files including "dirty" gdb headers so that +# successful compilations can be achieved with acceptable warnings; its +# usefulness is also dependent upon the processor's compiler -- your mileage +# may vary. +# +#WARNING_OPTIONS=-Wall -O2 -Wstrict-prototypes -Wmissing-prototypes -fstack-protector -Wformat-security +#WARNING_ERROR=-Werror + +# TARGET_CFLAGS will be configured automatically by configure +TARGET_CFLAGS= + +CRASH_CFLAGS=-g -D${TARGET} ${TARGET_CFLAGS} ${GDB_FLAGS} ${CFLAGS} + +GPL_FILES= +TAR_FILES=${SOURCE_FILES} Makefile ${GPL_FILES} README .rh_rpm_package crash.8 \ + ${EXTENSION_SOURCE_FILES} ${MEMORY_DRIVER_FILES} +CSCOPE_FILES=${SOURCE_FILES} + +READLINE_DIRECTORY=./${GDB}/readline +BFD_DIRECTORY=./${GDB}/bfd +GDB_INCLUDE_DIRECTORY=./${GDB}/include + +REDHATFLAGS=-DREDHAT + +# target could be set on command line when invoking make. Like: make target=ARM +# otherwise target will be the same as the host +ifneq ($(target),) +CONF_TARGET_FLAG="-t$(target)" +endif + +# To build the extensions library by default, uncomment the third command +# line below. Otherwise they can be built by entering "make extensions". + +all: make_configure + @./configure ${CONF_TARGET_FLAG} -p "RPMPKG=${RPMPKG}" -b + @make --no-print-directory gdb_merge +# @make --no-print-directory extensions + +gdb_merge: force + @if [ ! -f ${GDB}/README ]; then \ + make --no-print-directory gdb_unzip; fi + @echo "${LDFLAGS} -lz -ldl -rdynamic" > ${GDB}/gdb/mergelibs + @echo "../../${PROGRAM} ../../${PROGRAM}lib.a" > ${GDB}/gdb/mergeobj + @rm -f ${PROGRAM} + @if [ ! -f ${GDB}/config.status ]; then \ + (cd ${GDB}; ./configure ${GDB_CONF_FLAGS} --with-separate-debug-dir=/usr/lib/debug \ + --with-bugurl="" --with-expat=no --with-python=no; \ + make --no-print-directory CRASH_TARGET=${TARGET}; echo ${TARGET} > crash.target) \ + else (cd ${GDB}/gdb; make --no-print-directory CRASH_TARGET=${TARGET};); fi + @if [ ! -f ${PROGRAM} ]; then \ + echo; echo "${PROGRAM} build failed"; \ + echo; exit 1; fi + +gdb_unzip: + @rm -f gdb.files + @for FILE in ${GDB_FILES} dummy; do\ + echo $$FILE >> gdb.files; done + @if [ ! -f ${GDB}.tar.gz ] && [ -f /usr/bin/wget ]; then \ + wget http://ftp.gnu.org/gnu/gdb/${GDB}.tar.gz; fi + @tar --exclude-from gdb.files -xvzmf ${GDB}.tar.gz + @make --no-print-directory gdb_patch + +gdb_patch: + if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \ + patch -p0 < ${GDB}.patch; fi + +library: make_build_data ${OBJECT_FILES} + ar -rs ${PROGRAM}lib.a ${OBJECT_FILES} + +gdb: force + rm -f ${GDB_OFILES} + @make --no-print-directory all + +force: + + +make_configure: force + @rm -f configure + @${CC} ${CONF_FLAGS} -o configure configure.c ${WARNING_ERROR} ${WARNING_OPTIONS} + +clean: make_configure + @./configure ${CONF_TARGET_FLAG} -q -b + @make --no-print-directory do_clean + +do_clean: + rm -f ${OBJECT_FILES} ${DAEMON_OBJECT_FILES} ${PROGRAM} ${PROGRAM}lib.a ${GDB_OFILES} + @(cd extensions; make --no-print-directory -i clean) + @(cd memory_driver; make --no-print-directory -i clean) + +make_build_data: force + ${CC} -c ${CRASH_CFLAGS} build_data.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +install: + /usr/bin/install ${PROGRAM} ${INSTALLDIR} +# /usr/bin/install ${PROGRAM}d ${INSTALLDIR} + +unconfig: make_configure + @./configure -u + +warn: make_configure + @./configure ${CONF_TARGET_FLAG} -w -b + @make --no-print-directory gdb_merge + +Warn: make_configure + @./configure ${CONF_TARGET_FLAG} -W -b + @make --no-print-directory gdb_merge + +nowarn: make_configure + @./configure ${CONF_TARGET_FLAG} -n -b + @make --no-print-directory gdb_merge + +lzo: make_configure + @./configure -x lzo ${CONF_TARGET_FLAG} -w -b + @make --no-print-directory gdb_merge + +snappy: make_configure + @./configure -x snappy ${CONF_TARGET_FLAG} -w -b + @make --no-print-directory gdb_merge + +main.o: ${GENERIC_HFILES} main.c + ${CC} -c ${CRASH_CFLAGS} main.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +cmdline.o: ${GENERIC_HFILES} cmdline.c + ${CC} -c ${CRASH_CFLAGS} cmdline.c -I${READLINE_DIRECTORY} ${WARNING_OPTIONS} ${WARNING_ERROR} + +tools.o: ${GENERIC_HFILES} tools.c + ${CC} -c ${CRASH_CFLAGS} tools.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +global_data.o: ${GENERIC_HFILES} global_data.c + ${CC} -c ${CRASH_CFLAGS} global_data.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +symbols.o: ${GENERIC_HFILES} symbols.c + ${CC} -c ${CRASH_CFLAGS} symbols.c -I${BFD_DIRECTORY} -I${GDB_INCLUDE_DIRECTORY} ${WARNING_OPTIONS} ${WARNING_ERROR} + +filesys.o: ${GENERIC_HFILES} filesys.c + ${CC} -c ${CRASH_CFLAGS} filesys.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +help.o: ${GENERIC_HFILES} help.c + ${CC} -c ${CRASH_CFLAGS} help.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +memory.o: ${GENERIC_HFILES} memory.c + ${CC} -c ${CRASH_CFLAGS} memory.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +test.o: ${GENERIC_HFILES} test.c + ${CC} -c ${CRASH_CFLAGS} test.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +task.o: ${GENERIC_HFILES} task.c + ${CC} -c ${CRASH_CFLAGS} task.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +kernel.o: ${GENERIC_HFILES} kernel.c + ${CC} -c ${CRASH_CFLAGS} kernel.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +gdb_interface.o: ${GENERIC_HFILES} gdb_interface.c + ${CC} -c ${CRASH_CFLAGS} gdb_interface.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +va_server.o: ${MCORE_HFILES} va_server.c + ${CC} -c ${CRASH_CFLAGS} va_server.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +va_server_v1.o: ${MCORE_HFILES} va_server_v1.c + ${CC} -c ${CRASH_CFLAGS} va_server_v1.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +lkcd_common.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_common.c + ${CC} -c ${CRASH_CFLAGS} lkcd_common.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +lkcd_v1.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_v1.c + ${CC} -c ${CRASH_CFLAGS} lkcd_v1.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} + +lkcd_v2_v3.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_v2_v3.c + ${CC} -c ${CRASH_CFLAGS} lkcd_v2_v3.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} + +lkcd_v5.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_v5.c + ${CC} -c ${CRASH_CFLAGS} lkcd_v5.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} + +lkcd_v7.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_v7.c + ${CC} -c ${CRASH_CFLAGS} lkcd_v7.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} + +lkcd_v8.o: ${GENERIC_HFILES} ${LKCD_DUMP_HFILES} lkcd_v8.c + ${CC} -c ${CRASH_CFLAGS} lkcd_v8.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} + +net.o: ${GENERIC_HFILES} net.c + ${CC} -c ${CRASH_CFLAGS} net.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +dev.o: ${GENERIC_HFILES} dev.c + ${CC} -c ${CRASH_CFLAGS} dev.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +# remote.c functionality has been deprecated +remote.o: ${GENERIC_HFILES} remote.c + @${CC} -c ${CRASH_CFLAGS} remote.c ${WARNING_OPTIONS} ${WARNING_ERROR} +remote_daemon.o: ${GENERIC_HFILES} remote.c + ${CC} -c ${CRASH_CFLAGS} -DDAEMON remote.c -o remote_daemon.o ${WARNING_OPTIONS} ${WARNING_ERROR} + +x86.o: ${GENERIC_HFILES} ${REDHAT_HFILES} x86.c + ${CC} -c ${CRASH_CFLAGS} x86.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} + +alpha.o: ${GENERIC_HFILES} alpha.c + ${CC} -c ${CRASH_CFLAGS} alpha.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +ppc.o: ${GENERIC_HFILES} ppc.c + ${CC} -c ${CRASH_CFLAGS} ppc.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +ia64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} ia64.c + ${CC} -c ${CRASH_CFLAGS} ia64.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +ppc64.o: ${GENERIC_HFILES} ppc64.c + ${CC} -c ${CRASH_CFLAGS} ppc64.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +x86_64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} x86_64.c + ${CC} -c ${CRASH_CFLAGS} x86_64.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +arm.o: ${GENERIC_HFILES} ${REDHAT_HFILES} arm.c + ${CC} -c ${CRASH_CFLAGS} arm.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +arm64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} arm64.c + ${CC} -c ${CRASH_CFLAGS} arm64.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +s390.o: ${GENERIC_HFILES} ${IBM_HFILES} s390.c + ${CC} -c ${CRASH_CFLAGS} s390.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +s390x.o: ${GENERIC_HFILES} ${IBM_HFILES} s390x.c + ${CC} -c ${CRASH_CFLAGS} s390x.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +s390dbf.o: ${GENERIC_HFILES} ${IBM_HFILES} s390dbf.c + ${CC} -c ${CRASH_CFLAGS} s390dbf.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +s390_dump.o: ${GENERIC_HFILES} ${IBM_HFILES} s390_dump.c + ${CC} -c ${CRASH_CFLAGS} s390_dump.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +netdump.o: ${GENERIC_HFILES} ${REDHAT_HFILES} ${SADUMP_HFILES} netdump.c + ${CC} -c ${CRASH_CFLAGS} netdump.c ${WARNING_OPTIONS} ${WARNING_ERROR} +netdump_daemon.o: ${GENERIC_HFILES} ${REDHAT_HFILES} netdump.c + ${CC} -c ${CRASH_CFLAGS} -DDAEMON netdump.c -o netdump_daemon.o ${WARNING_OPTIONS} ${WARNING_ERROR} + +diskdump.o: ${GENERIC_HFILES} ${REDHAT_HFILES} diskdump.c + ${CC} -c ${CRASH_CFLAGS} diskdump.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +makedumpfile.o: ${GENERIC_HFILES} ${REDHAT_HFILES} makedumpfile.c + ${CC} -c ${CRASH_CFLAGS} makedumpfile.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +xendump.o: ${GENERIC_HFILES} ${REDHAT_HFILES} xendump.c + ${CC} -c ${CRASH_CFLAGS} xendump.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +kvmdump.o: ${GENERIC_HFILES} ${REDHAT_HFILES} kvmdump.c + ${CC} -c ${CRASH_CFLAGS} kvmdump.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +qemu.o: ${GENERIC_HFILES} ${REDHAT_HFILES} qemu.c + ${CC} -c ${CRASH_CFLAGS} qemu.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +qemu-load.o: ${GENERIC_HFILES} ${REDHAT_HFILES} qemu-load.c + ${CC} -c ${CRASH_CFLAGS} qemu-load.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +sadump.o: ${GENERIC_HFILES} ${SADUMP_HFILES} sadump.c + ${CC} -c ${CRASH_CFLAGS} sadump.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +ipcs.o: ${GENERIC_HFILES} ipcs.c + ${CC} -c ${CRASH_CFLAGS} ipcs.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +extensions.o: ${GENERIC_HFILES} extensions.c + ${CC} -c ${CRASH_CFLAGS} extensions.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +lkcd_x86_trace.o: ${GENERIC_HFILES} ${LKCD_TRACE_HFILES} lkcd_x86_trace.c + ${CC} -c ${CRASH_CFLAGS} lkcd_x86_trace.c -DREDHAT ${WARNING_OPTIONS} ${WARNING_ERROR} + +unwind_x86_32_64.o: ${GENERIC_HFILES} ${UNWIND_HFILES} unwind_x86_32_64.c + ${CC} -c ${CRASH_CFLAGS} unwind_x86_32_64.c -o unwind_x86_32_64.o ${WARNING_OPTIONS} ${WARNING_ERROR} + +unwind_arm.o: ${GENERIC_HFILES} ${UNWIND_HFILES} unwind_arm.c + ${CC} -c ${CRASH_CFLAGS} unwind_arm.c -o unwind_arm.o ${WARNING_OPTIONS} ${WARNING_ERROR} + +unwind_v1.o: ${GENERIC_HFILES} ${UNWIND_HFILES} unwind.c unwind_decoder.c + ${CC} -c ${CRASH_CFLAGS} unwind.c -DREDHAT -DUNWIND_V1 -o unwind_v1.o ${WARNING_OPTIONS} ${WARNING_ERROR} + +unwind_v2.o: ${GENERIC_HFILES} ${UNWIND_HFILES} unwind.c unwind_decoder.c + ${CC} -c ${CRASH_CFLAGS} unwind.c -DREDHAT -DUNWIND_V2 -o unwind_v2.o ${WARNING_OPTIONS} ${WARNING_ERROR} + +unwind_v3.o: ${GENERIC_HFILES} ${UNWIND_HFILES} unwind.c unwind_decoder.c + ${CC} -c ${CRASH_CFLAGS} unwind.c -DREDHAT -DUNWIND_V3 -o unwind_v3.o ${WARNING_OPTIONS} ${WARNING_ERROR} + +lkcd_fix_mem.o: ${GENERIC_HFILES} ${LKCD_HFILES} lkcd_fix_mem.c + ${CC} -c ${CRASH_CFLAGS} lkcd_fix_mem.c -DMCLX ${WARNING_OPTIONS} ${WARNING_ERROR} + +xen_hyper.o: ${GENERIC_HFILES} xen_hyper.c + ${CC} -c ${CRASH_CFLAGS} xen_hyper.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +xen_hyper_command.o: ${GENERIC_HFILES} xen_hyper_command.c + ${CC} -c ${CRASH_CFLAGS} xen_hyper_command.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +xen_hyper_global_data.o: ${GENERIC_HFILES} xen_hyper_global_data.c + ${CC} -c ${CRASH_CFLAGS} xen_hyper_global_data.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +xen_hyper_dump_tables.o: ${GENERIC_HFILES} xen_hyper_dump_tables.c + ${CC} -c ${CRASH_CFLAGS} xen_hyper_dump_tables.c ${WARNING_OPTIONS} ${WARNING_ERROR} + +${PROGRAM}: force + @make --no-print-directory all + +# Remote daemon functionality has been deprecated. +daemon_deprecated: force + @echo "WARNING: remote daemon functionality has been deprecated" + @echo + +${PROGRAM}d: daemon_deprecated make_configure + @./configure -d + @make --no-print-directory make_build_data + @make --no-print-directory daemon + +daemon: ${DAEMON_OBJECT_FILES} + ${CC} ${LDFLAGS} -o ${PROGRAM}d ${DAEMON_OBJECT_FILES} build_data.o -lz + +files: make_configure + @./configure -q -b + @make --no-print-directory show_files + +gdb_files: make_configure + @./configure -q -b + @echo ${GDB_FILES} ${GDB_PATCH_FILES} + +show_files: + @if [ -f ${PROGRAM} ]; then \ + ./${PROGRAM} --no_scroll --no_crashrc -h README > README; fi + @echo ${SOURCE_FILES} Makefile ${GDB_FILES} ${GDB_PATCH_FILES} ${GPL_FILES} README \ + .rh_rpm_package crash.8 ${EXTENSION_SOURCE_FILES} ${MEMORY_DRIVER_FILES} + +ctags: + ctags ${SOURCE_FILES} + +tar: make_configure + @./configure -q -b + @make --no-print-directory do_tar + +do_tar: + @if [ -f ${PROGRAM} ]; then \ + ./${PROGRAM} --no_scroll --no_crashrc -h README > README; fi + tar cvzf ${PROGRAM}.tar.gz ${TAR_FILES} ${GDB_FILES} ${GDB_PATCH_FILES} + @echo; ls -l ${PROGRAM}.tar.gz + +VERSION= +RELEASE=0 + +release: make_configure + @if [ "`id --user`" != "0" ]; then \ + echo "make release: must be super-user"; exit 1; fi + @./configure -P "RPMPKG=${RPMPKG}" -u -g + @make --no-print-directory release_configure + @echo + @echo "cvs tag this release if necessary" + +release_configure: make_configure + @if [ "${GDB}" = "" ] ; then \ + echo "make release: GDB not defined: append GDB=gdb-x.x to make command line"; echo; exit 1; fi + @./configure -r ${GDB} + @make --no-print-directory do_release + +do_release: + @echo "CRASH VERSION: ${VERSION} GDB VERSION: ${GDB}" + @if [ ! -f .rh_rpm_package ]; then \ + echo "no .rh_rpm_package exists!"; exit 1; fi + @chmod 666 .rh_rpm_package + @rm -rf ./RELDIR; mkdir ./RELDIR; mkdir ./RELDIR/${PROGRAM}-${VERSION} + @rm -f ${PROGRAM}-${VERSION}.tar.gz + @rm -f ${PROGRAM}-${VERSION}-${RELEASE}.src.rpm + @chown root ./RELDIR/${PROGRAM}-${VERSION} + @tar cf - ${SOURCE_FILES} Makefile ${GDB_FILES} ${GDB_PATCH_FILES} ${GPL_FILES} \ + .rh_rpm_package crash.8 ${EXTENSION_SOURCE_FILES} ${MEMORY_DRIVER_FILES} | \ + (cd ./RELDIR/${PROGRAM}-${VERSION}; tar xf -) + @cp ${GDB}.tar.gz ./RELDIR/${PROGRAM}-${VERSION} + @./${PROGRAM} --no_scroll --no_crashrc -h README > ./RELDIR/${PROGRAM}-${VERSION}/README + @(cd ./RELDIR; find . -exec chown root {} ";") + @(cd ./RELDIR; find . -exec chgrp root {} ";") + @(cd ./RELDIR; find . -exec touch {} ";") + @(cd ./RELDIR; \ + tar czvf ../${PROGRAM}-${VERSION}.tar.gz ${PROGRAM}-${VERSION}) + @chgrp root ${PROGRAM}-${VERSION}.tar.gz + @rm -rf ./RELDIR + @echo + @ls -l ${PROGRAM}-${VERSION}.tar.gz + @./configure -s -u > ${PROGRAM}.spec + @if [ -s ${PROGRAM}.spec ]; then \ + rm -rf ./RPMBUILD; \ + mkdir -p ./RPMBUILD/SOURCES ./RPMBUILD/SPECS ./RPMBUILD/SRPMS; \ + cp ${PROGRAM}-${VERSION}.tar.gz ./RPMBUILD/SOURCES; \ + cp ${PROGRAM}.spec ./RPMBUILD/SPECS; \ + rpmbuild --define "_sourcedir ./RPMBUILD/SOURCES" \ + --define "_srcrpmdir ./RPMBUILD/SRPMS" \ + --define "_specdir ./RPMBUILD/SPECS" \ + --nodeps -bs ./RPMBUILD/SPECS/${PROGRAM}.spec > /dev/null; \ + mv ./RPMBUILD/SRPMS/${PROGRAM}-${VERSION}-${RELEASE}.src.rpm . ; \ + rm -rf ./RPMBUILD; \ + ls -l ${PROGRAM}-${VERSION}-${RELEASE}.src.rpm; \ + fi + +ref: + make ctags cscope + +cscope: + rm -f cscope.files cscope_out + for FILE in ${SOURCE_FILES}; do \ + echo $$FILE >> cscope.files; done + cscope + +glink: make_configure + @./configure -q -b + rm -f gdb + ln -s ${GDB}/gdb gdb + (cd ${GDB}/gdb; rm -f ${PROGRAM}; ln -s ../../${PROGRAM} ${PROGRAM}) + +name: + @echo ${PROGRAM} + +dis: + objdump --disassemble --line-numbers ${PROGRAM} > ${PROGRAM}.dis + +extensions: make_configure + @./configure ${CONF_TARGET_FLAG} -q -b + @make --no-print-directory do_extensions + +do_extensions: + @(cd extensions; make -i TARGET=$(TARGET) TARGET_CFLAGS="$(TARGET_CFLAGS)" GDB=$(GDB) GDB_FLAGS=$(GDB_FLAGS)) + +memory_driver: make_configure + @(cd memory_driver; make --no-print-directory -i) diff --git a/README b/README new file mode 100644 index 00000000..e2aa03d9 --- /dev/null +++ b/README @@ -0,0 +1,355 @@ + + + CORE ANALYSIS SUITE + + The core analysis suite is a self-contained tool that can be used to + investigate either live systems, kernel core dumps created from dump + creation facilities such as kdump, kvmdump, xendump, the netdump and + diskdump packages offered by Red Hat, the LKCD kernel patch, the mcore + kernel patch created by Mission Critical Linux, as well as other formats + created by manufacturer-specific firmware. + + o The tool is loosely based on the SVR4 crash command, but has been + completely integrated with gdb in order to be able to display + formatted kernel data structures, disassemble source code, etc. + + o The current set of available commands consist of common kernel core + analysis tools such as a context-specific stack traces, source code + disassembly, kernel variable displays, memory display, dumps of + linked-lists, etc. In addition, any gdb command may be entered, + which in turn will be passed onto the gdb module for execution. + + o There are several commands that delve deeper into specific kernel + subsystems, which also serve as templates for kernel developers + to create new commands for analysis of a specific area of interest. + Adding a new command is a simple affair, and a quick recompile + adds it to the command menu. + + o The intent is to make the tool independent of Linux version dependencies, + building in recognition of major kernel code changes so as to adapt to + new kernel versions, while maintaining backwards compatibility. + + A whitepaper with complete documentation concerning the use of this utility + can be found here: + + http://people.redhat.com/anderson/crash_whitepaper + + These are the current prerequisites: + + o At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, s390 + and s390x-based kernels are supported. Other architectures may be + addressed in the future. + + o One size fits all -- the utility can be run on any Linux kernel version + version dating back to 2.2.5-15. A primary design goal is to always + maintain backwards-compatibility. + + o In order to contain debugging data, the top-level kernel Makefile's CFLAGS + definition must contain the -g flag. Typically distributions will contain + a package containing a vmlinux file with full debuginfo data. If not, the + kernel must be rebuilt: + + For 2.2 kernels that are not built with -g, change the following line: + + CFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer + + to: + + CFLAGS = -g -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer + + For 2.4 kernels that are not built with -g, change the following line: + + CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing + + to: + + CFLAGS := -g $(CPPFLAGS) -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing + + For 2.6 and later kernels that are not built with -g, the kernel should + be configured with CONFIG_DEBUG_INFO enabled, which in turn will add + the -g flag to the CFLAGS setting in the kernel Makefile. + + After the kernel is re-compiled, the uncompressed "vmlinux" kernel + that is created in the top-level kernel build directory must be saved. + + To build the crash utility: + + $ tar -xf crash-7.0.4.tar.gz + $ cd crash-7.0.4 + $ make + + The initial build will take several minutes because the embedded gdb module + must be configured and and built. Alternatively, the crash source RPM file + may be installed and built, and the resultant crash binary RPM file installed. + + The crash binary can only be used on systems of the same architecture as + the host build system. There are a few optional manners of building the + crash binary: + + o On an x86_64 host, a 32-bit x86 binary that can be used to analyze + 32-bit x86 dumpfiles may be built by typing "make target=X86". + o On an x86 or x86_64 host, a 32-bit x86 binary that can be used to analyze + 32-bit arm dumpfiles may be built by typing "make target=ARM". + o On an ppc64 host, a 32-bit ppc binary that can be used to analyze + 32-bit ppc dumpfiles may be built by typing "make target=PPC". + o On an x86_64 host, an x86_64 binary that can be used to analyze + arm64 dumpfiles may be built by typing "make target=ARM64". + + Traditionally when vmcores are compressed via the makedumpfile(8) facility + the libz compression library is used, and by default the crash utility + only supports libz. Recently makedumpfile has been enhanced to optionally + use either the LZO or snappy compression libraries. To build crash with + either or both of those libraries, type "make lzo" or "make snappy". + + All of the alternate build commands above are "sticky" in that the + special "make" targets only have to be entered one time; all subsequent + builds will follow suit. + + If the tool is run against a kernel dumpfile, two arguments are required, the + uncompressed kernel name and the kernel dumpfile name. + + If run on a live system, only the kernel name is required, because /dev/mem + will be used as the "dumpfile". On Red Hat or Fedora kernels where the + /dev/mem device is restricted, the /dev/crash memory driver will be used. + If neither /dev/mem or /dev/crash are available, then /proc/kcore will be + be used as the live memory source. If /proc/kcore is also restricted, then + the Red Hat /dev/crash driver may be compiled and installed; its source + is included in the crash-7.0.4/memory_driver subdirectory. + + If the kernel file is stored in /boot, /, /boot/efi, or in any /usr/src + or /usr/lib/debug/lib/modules subdirectory, then no command line arguments + are required -- the first kernel found that matches /proc/version will be + used as the namelist. + + For example, invoking crash on a live system would look like this: + + $ crash + + crash 7.0.4 + Copyright (C) 2002-2013 Red Hat, Inc. + Copyright (C) 2004, 2005, 2006, 2010 IBM Corporation + Copyright (C) 1999-2006 Hewlett-Packard Co + Copyright (C) 2005, 2006, 2011, 2012 Fujitsu Limited + Copyright (C) 2006, 2007 VA Linux Systems Japan K.K. + Copyright (C) 2005, 2011 NEC Corporation + Copyright (C) 1999, 2002, 2007 Silicon Graphics, Inc. + Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. + This program is free software, covered by the GNU General Public License, + and you are welcome to change it and/or distribute copies of it under + certain conditions. Enter "help copying" to see the conditions. + This program has absolutely no warranty. Enter "help warranty" for details. + + GNU gdb 7.6 + Copyright 2013 Free Software Foundation, Inc. + License GPLv3+: GNU GPL version 3 or later + This is free software: you are free to change and redistribute it. + There is NO WARRANTY, to the extent permitted by law. Type "show copying" + and "show warranty" for details. + This GDB was configured as "i686-pc-linux-gnu"... + + KERNEL: /boot/vmlinux + DUMPFILE: /dev/mem + CPUS: 1 + DATE: Wed Dec 11 15:57:58 2013 + UPTIME: 10 days, 22:55:18 + LOAD AVERAGE: 0.08, 0.03, 0.01 + TASKS: 42 + NODENAME: ha2.mclinux.com + RELEASE: 2.4.0-test10 + VERSION: #11 SMP Thu Nov 4 15:09:25 EST 2000 + MACHINE: i686 (447 MHz) + MEMORY: 128 MB + PID: 3621 + COMMAND: "crash" + TASK: c463c000 + CPU: 0 + STATE: TASK_RUNNING (ACTIVE) + + crash> help + + * files mach repeat timer + alias foreach mod runq tree + ascii fuser mount search union + bt gdb net set vm + btop help p sig vtop + dev ipcs ps struct waitq + dis irq pte swap whatis + eval kmem ptob sym wr + exit list ptov sys q + extend log rd task + + crash version: 7.0.4 gdb version: 7.6 + For help on any command above, enter "help ". + For help on input options, enter "help input". + For help on output options, enter "help output". + + crash> + + When run on a dumpfile, both the kernel namelist and dumpfile must be + entered on the command line. For example, when run on a core dump created + by the Red Hat netdump or diskdump facilities: + + $ crash vmlinux vmcore + + crash 7.0.4 + Copyright (C) 2002-2013 Red Hat, Inc. + Copyright (C) 2004, 2005, 2006, 2010 IBM Corporation + Copyright (C) 1999-2006 Hewlett-Packard Co + Copyright (C) 2005, 2006, 2011, 2012 Fujitsu Limited + Copyright (C) 2006, 2007 VA Linux Systems Japan K.K. + Copyright (C) 2005, 2011 NEC Corporation + Copyright (C) 1999, 2002, 2007 Silicon Graphics, Inc. + Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. + This program is free software, covered by the GNU General Public License, + and you are welcome to change it and/or distribute copies of it under + certain conditions. Enter "help copying" to see the conditions. + This program has absolutely no warranty. Enter "help warranty" for details. + + GNU gdb 7.6 + Copyright 2013 Free Software Foundation, Inc. + License GPLv3+: GNU GPL version 3 or later + This is free software: you are free to change and redistribute it. + There is NO WARRANTY, to the extent permitted by law. Type "show copying" + and "show warranty" for details. + This GDB was configured as "i686-pc-linux-gnu"... + + KERNEL: vmlinux + DUMPFILE: vmcore + CPUS: 4 + DATE: Tue Mar 2 13:57:09 2004 + UPTIME: 00:02:40 + LOAD AVERAGE: 2.24, 0.96, 0.37 + TASKS: 70 + NODENAME: pro1.lab.boston.redhat.com + RELEASE: 2.6.3-2.1.214.11smp + VERSION: #1 SMP Tue Mar 2 10:58:27 EST 2004 + MACHINE: i686 (2785 Mhz) + MEMORY: 512 MB + PANIC: "Oops: 0002 [#1]" (check log for details) + PID: 0 + COMMAND: "swapper" + TASK: 22fa200 (1 of 4) [THREAD_INFO: 2356000] + CPU: 0 + STATE: TASK_RUNNING (PANIC) + + crash> + + The tool's environment is context-specific. On a live system, the default + context is the command itself; on a dump the default context will be the + task that panicked. The most commonly-used commands are: + + set - set a new task context by pid, task address, or cpu. + bt - backtrace of the current context, or as specified with arguments. + p - print the contents of a kernel variable. + rd - read memory, which may be either kernel virtual, user virtual, or + physical. + ps - simple process listing. + log - dump the kernel log_buf. + struct - print the contents of a structure at a specified address. + foreach - execute a command on all tasks, or those specified, in the system. + + Detailed help concerning the use of each of the commands in the menu above + may be displayed by entering "help command", where "command" is one of those + listed above. Rather than getting bogged down in details here, simply + run the help command on each of the commands above. Note that many commands + have multiple options so as to avoid the proliferation of command names. + + Command output may be piped to external commands or redirected to files. + Enter "help output" for details. + + The command line history mechanism allows for command-line recall and + command-line editing. Input files containing a set of crash commands may + be substituted for command-line input. Enter "help input" for details. + + Note that a .crashrc file (or .rc if the name has been + changed), may contain any number of "set" or "alias" commands -- see the + help pages on those two commands for details. + + Lastly, if a command is entered that is not recognized, it is checked + against the kernel's list of variables, structure, union or typedef names, + and if found, the command is passed to "p", "struct", "union" or "whatis". + That being the case, as long as a kernel variable/structure/union name is + different than any of the current commands. + + (1) A kernel variable can be dumped by simply entering its name: + + crash> init_mm + init_mm = $2 = { + mmap = 0xc022d540, + mmap_avl = 0x0, + mmap_cache = 0x0, + pgd = 0xc0101000, + count = { + counter = 0x6 + }, + map_count = 0x1, + mmap_sem = { + count = { + counter = 0x1 + }, + waking = 0x0, + wait = 0x0 + }, + context = 0x0, + start_code = 0xc0000000, + end_code = 0xc022b4c8, + end_data = c0250388, + ... + + (2) A structure or can be dumped simply by entering its name and address: + + crash> vm_area_struct c5ba3910 + struct vm_area_struct { + vm_mm = 0xc3ae3210, + vm_start = 0x821b000, + vm_end = 0x8692000, + vm_next = 0xc5ba3890, + vm_page_prot = { + pgprot = 0x25 + }, + vm_flags = 0x77, + vm_avl_height = 0x4, + vm_avl_left = 0xc0499540, + vm_avl_right = 0xc0499f40, + vm_next_share = 0xc04993c0, + vm_pprev_share = 0xc0499060, + vm_ops = 0x0, + vm_offset = 0x0, + vm_file = 0x0, + vm_pte = 0x0 + } + + + The crash utility has been designed to facilitate the task of adding new + commands. New commands may be permanently compiled into the crash executable, + or dynamically added during runtime using shared object files. + + To permanently add a new command to the crash executable's menu: + + 1. For a command named "xxx", put a reference to cmd_xxx() in defs.h. + + 2. Add cmd_xxx into the base_command_table[] array in global_data.c. + + 3. Write cmd_xxx(), putting it in one of the appropriate files. Look at + the other commands for guidance on getting symbolic data, reading + memory, displaying data, etc... + + 4. Recompile and run. + + Note that while the initial compile of crash, which configures and compiles + the gdb module, takes several minutes, subsequent re-compiles to do such + things as add new commands or fix bugs just takes a few seconds. + + Alternatively, you can create shared object library files consisting of + crash command extensions, that can be dynamically linked into the crash + executable during runtime or during initialization. This will allow the + the same shared object to be used with subsequent crash releases without + having to re-merge the command's code into each new set of crash sources. + The dynamically linked-in commands will automatically show up in the crash + help menu. For details, enter "help extend" during runtime, or enter + "crash -h extend" from the shell command line. + + + + + diff --git a/alpha.c b/alpha.c new file mode 100644 index 00000000..fa2d5f59 --- /dev/null +++ b/alpha.c @@ -0,0 +1,2733 @@ +/* alpha.c - core analysis suite + * + * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2006, 2010-2013 David Anderson + * Copyright (C) 2002-2006, 2010-2013 Red Hat, Inc. 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. + * + */ +#ifdef ALPHA +#include "defs.h" + +static void alpha_back_trace(struct gnu_request *, struct bt_info *); +static int alpha_trace_status(struct gnu_request *, struct bt_info *); +static void alpha_exception_frame(ulong, ulong, + struct gnu_request *, struct bt_info *); +static void alpha_frame_offset(struct gnu_request *, ulong); +static int alpha_backtrace_resync(struct gnu_request *, ulong, + struct bt_info *); +static void alpha_print_stack_entry(struct gnu_request *, ulong, + char *, ulong, struct bt_info *); +static int alpha_resync_speculate(struct gnu_request *, ulong,struct bt_info *); +static int alpha_dis_filter(ulong, char *, unsigned int); +static void dis_address_translation(ulong, char *, unsigned int); +static void alpha_cmd_mach(void); +static int alpha_get_smp_cpus(void); +static void alpha_display_machine_stats(void); +static void alpha_dump_line_number(char *, ulong); +static void display_hwrpb(unsigned int); +static void alpha_post_init(void); +static struct line_number_hook alpha_line_number_hooks[]; + + +#define ALPHA_CONTINUE_TRACE (1) +#define ALPHA_END_OF_TRACE (2) +#define ALPHA_EXCEPTION_FRAME (3) +#define ALPHA_SYSCALL_FRAME (4) +#define ALPHA_MM_FAULT (5) +#define ALPHA_INTERRUPT_PENDING (6) +#define ALPHA_RESCHEDULE (7) +#define ALPHA_DOWN_FAILED (8) +#define ALPHA_RET_FROM_SMP_FORK (9) +#define ALPHA_SIGNAL_RETURN (10) +#define ALPHA_STRACE (11) + +static int alpha_eframe_search(struct bt_info *); +static int alpha_uvtop(struct task_context *, ulong, physaddr_t *, int); +static int alpha_kvtop(struct task_context *, ulong, physaddr_t *, int); +static void alpha_back_trace_cmd(struct bt_info *); +static ulong alpha_get_task_pgd(ulong task); +static ulong alpha_processor_speed(void); +static void alpha_dump_irq(int); +static void alpha_get_stack_frame(struct bt_info *, ulong *, ulong *); +static void get_alpha_frame(struct bt_info *, ulong *, ulong *); +static int verify_user_eframe(struct bt_info *, ulong, ulong); +static int alpha_translate_pte(ulong, void *, ulonglong); +static uint64_t alpha_memory_size(void); +static ulong alpha_vmalloc_start(void); +static int alpha_is_task_addr(ulong); +static int alpha_verify_symbol(const char *, ulong, char); + +struct percpu_data { + ulong halt_PC; + ulong halt_ra; + ulong halt_pv; +}; +#define GET_HALT_PC 0x1 +#define GET_HALT_RA 0x2 +#define GET_HALT_PV 0x3 +static ulong get_percpu_data(int, ulong, struct percpu_data *); + +/* + * Do all necessary machine-specific setup here. This is called three times, + * before symbol table initialization, and before and after GDB has been + * initialized. + */ +void +alpha_init(int when) +{ + int tmp; + + switch (when) + { + case PRE_SYMTAB: + machdep->verify_symbol = alpha_verify_symbol; + if (pc->flags & KERNEL_DEBUG_QUERY) + return; + machdep->pagesize = memory_page_size(); + machdep->pageshift = ffs(machdep->pagesize) - 1; + machdep->pageoffset = machdep->pagesize - 1; + machdep->pagemask = ~(machdep->pageoffset); + machdep->stacksize = machdep->pagesize * 2; + if ((machdep->pgd = (char *)malloc(PAGESIZE())) == NULL) + error(FATAL, "cannot malloc pgd space."); + if ((machdep->pmd = (char *)malloc(PAGESIZE())) == NULL) + error(FATAL, "cannot malloc pmd space."); + if ((machdep->ptbl = (char *)malloc(PAGESIZE())) == NULL) + error(FATAL, "cannot malloc ptbl space."); + machdep->last_pgd_read = 0; + machdep->last_pmd_read = 0; + machdep->last_ptbl_read = 0; + machdep->verify_paddr = generic_verify_paddr; + machdep->ptrs_per_pgd = PTRS_PER_PGD; + break; + + case PRE_GDB: + switch (symbol_value("_stext") & KSEG_BASE) + { + case KSEG_BASE: + machdep->kvbase = KSEG_BASE; + break; + + case KSEG_BASE_48_BIT: + machdep->kvbase = KSEG_BASE_48_BIT; + break; + + default: + error(FATAL, + "cannot determine KSEG base from _stext: %lx\n", + symbol_value("_stext")); + } + + machdep->identity_map_base = machdep->kvbase; + machdep->is_kvaddr = generic_is_kvaddr; + machdep->is_uvaddr = generic_is_uvaddr; + machdep->eframe_search = alpha_eframe_search; + machdep->back_trace = alpha_back_trace_cmd; + machdep->processor_speed = alpha_processor_speed; + machdep->uvtop = alpha_uvtop; + machdep->kvtop = alpha_kvtop; + machdep->get_task_pgd = alpha_get_task_pgd; + if (symbol_exists("irq_desc")) + machdep->dump_irq = generic_dump_irq; + else + machdep->dump_irq = alpha_dump_irq; + machdep->get_stack_frame = alpha_get_stack_frame; + machdep->get_stackbase = generic_get_stackbase; + machdep->get_stacktop = generic_get_stacktop; + machdep->translate_pte = alpha_translate_pte; + machdep->memory_size = alpha_memory_size; + machdep->vmalloc_start = alpha_vmalloc_start; + machdep->is_task_addr = alpha_is_task_addr; + if (symbol_exists("console_crash")) { + get_symbol_data("console_crash", sizeof(int), &tmp); + if (tmp) + machdep->flags |= HWRESET; + } + machdep->dis_filter = alpha_dis_filter; + machdep->cmd_mach = alpha_cmd_mach; + machdep->get_smp_cpus = alpha_get_smp_cpus; + machdep->line_number_hooks = alpha_line_number_hooks; + machdep->value_to_symbol = generic_machdep_value_to_symbol; + machdep->init_kernel_pgd = NULL; + break; + + case POST_GDB: + MEMBER_OFFSET_INIT(thread_struct_ptbr, + "thread_struct", "ptbr"); + MEMBER_OFFSET_INIT(hwrpb_struct_cycle_freq, + "hwrpb_struct", "cycle_freq"); + MEMBER_OFFSET_INIT(hwrpb_struct_processor_offset, + "hwrpb_struct", "processor_offset"); + MEMBER_OFFSET_INIT(hwrpb_struct_processor_size, + "hwrpb_struct", "processor_size"); + MEMBER_OFFSET_INIT(percpu_struct_halt_PC, + "percpu_struct", "halt_PC"); + MEMBER_OFFSET_INIT(percpu_struct_halt_ra, + "percpu_struct", "halt_ra"); + MEMBER_OFFSET_INIT(percpu_struct_halt_pv, + "percpu_struct", "halt_pv"); + MEMBER_OFFSET_INIT(switch_stack_r26, + "switch_stack", "r26"); + if (symbol_exists("irq_action")) + ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_action, + "irq_action", NULL, 0); + else if (symbol_exists("irq_desc")) + ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc, + "irq_desc", NULL, 0); + else + machdep->nr_irqs = 0; + if (!machdep->hz) + machdep->hz = HZ; + break; + + case POST_INIT: + alpha_post_init(); + break; + } +} + +/* + * Unroll a kernel stack. + */ +static void +alpha_back_trace_cmd(struct bt_info *bt) +{ + char buf[BUFSIZE]; + struct gnu_request *req; + + bt->flags |= BT_EXCEPTION_FRAME; + + if (CRASHDEBUG(1) || bt->debug) + fprintf(fp, " => PC: %lx (%s) FP: %lx \n", + bt->instptr, value_to_symstr(bt->instptr, buf, 0), + bt->stkptr ); + + req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request)); + req->command = GNU_STACK_TRACE; + req->flags = GNU_RETURN_ON_ERROR; + req->buf = GETBUF(BUFSIZE); + req->debug = bt->debug; + req->task = bt->task; + + req->pc = bt->instptr; + req->sp = bt->stkptr; + + if (bt->flags & BT_USE_GDB) { + strcpy(req->buf, "backtrace"); + gdb_interface(req); + } + else + alpha_back_trace(req, bt); + + FREEBUF(req->buf); + FREEBUF(req); +} + + +/* + * Unroll the kernel stack. + */ + +#define ALPHA_BACKTRACE_SPECULATE(X) \ +{ \ + speculate_location = X; \ + \ + if (bt->flags & BT_SPECULATE) \ + return; \ + \ + BZERO(btloc, sizeof(struct bt_info)); \ + btloc->task = req->task; \ + btloc->tc = bt->tc; \ + btloc->stackbase = bt->stackbase; \ + btloc->stacktop = bt->stacktop; \ + btloc->flags = BT_TEXT_SYMBOLS_NOPRINT; \ + hook.eip = 0; \ + hook.esp = req->lastsp ? req->lastsp + sizeof(long) : 0; \ + btloc->hp = &hook; \ + \ + back_trace(btloc); \ + \ + if (hook.esp && hook.eip) { \ + req->hookp = &hook; \ + if (alpha_resync_speculate(req, bt->flags, bt)) { \ + req->pc = hook.eip; \ + req->sp = hook.esp; \ + continue; \ + } \ + goto show_remaining_text; \ + } \ + goto show_remaining_text; \ +} + + +static void +alpha_back_trace(struct gnu_request *req, struct bt_info *bt) +{ + char buf[BUFSIZE]; + int frame; + int done; + int status; + struct stack_hook hook; + int eframe_same_pc_ra_function; + int speculate_location; + struct bt_info bt_info, *btloc; + + frame = 0; + req->curframe = 0; + btloc = &bt_info; + + if (!IS_KVADDR(req->pc)) { + if (BT_REFERENCE_CHECK(bt)) + return; + + if ((machdep->flags & HWRESET) && is_task_active(req->task)) { + fprintf(fp, "(hardware reset while in user space)\n"); + return; + } + + fprintf(fp, "invalid pc: %lx\n", req->pc); + + alpha_exception_frame(USER_EFRAME_ADDR(req->task), + BT_USER_EFRAME, req, bt); + + return; + } + + + for (done = FALSE; !done && (frame < 100); frame++) { + + speculate_location = 0; + + if ((req->name = closest_symbol(req->pc)) == NULL) { + req->ra = req->pc = 0; + if (alpha_backtrace_resync(req, + bt->flags | BT_FROM_CALLFRAME, bt)) + continue; + + if (BT_REFERENCE_FOUND(bt)) + return; + + ALPHA_BACKTRACE_SPECULATE(1); + } + + if (!INSTACK(req->sp, bt)) + break; + + if (!is_kernel_text(req->pc)) + ALPHA_BACKTRACE_SPECULATE(2); + + alpha_print_stack_entry(req, req->pc, req->name, + bt->flags | BT_SAVE_LASTSP, bt); + + if (BT_REFERENCE_FOUND(bt)) + return; + + switch (status = alpha_trace_status(req, bt)) + { + case ALPHA_CONTINUE_TRACE: + alpha_frame_offset(req, 0); + if (!req->value) { + done = TRUE; + break; + } + req->prevpc = req->pc; + req->pc = GET_STACK_ULONG(req->sp); + req->prevsp = req->sp; + req->sp += req->value; + break; + + case ALPHA_END_OF_TRACE: + done = TRUE; + break; + + case ALPHA_STRACE: + alpha_exception_frame(req->sp, + BT_USER_EFRAME|BT_STRACE, req, bt); + done = TRUE; + break; + + case ALPHA_RET_FROM_SMP_FORK: + alpha_exception_frame(USER_EFRAME_ADDR(req->task), + BT_USER_EFRAME|BT_RET_FROM_SMP_FORK, req, bt); + done = TRUE; + break; + + case ALPHA_DOWN_FAILED: + frame++; + alpha_print_stack_entry(req, + req->pc, closest_symbol(req->pc), + bt->flags | BT_SAVE_LASTSP, bt); + + if (BT_REFERENCE_FOUND(bt)) + return; + + alpha_frame_offset(req, 0); + if (!req->value) { + done = TRUE; + break; + } + req->prevpc = req->pc; + req->pc = GET_STACK_ULONG(req->sp); + req->prevsp = req->sp; + req->sp += req->value; + break; + + case ALPHA_RESCHEDULE: + alpha_exception_frame(USER_EFRAME_ADDR(req->task), + BT_USER_EFRAME|BT_RESCHEDULE, req, bt); + done = TRUE; + break; + + case ALPHA_MM_FAULT: + alpha_exception_frame(req->sp, bt->flags, req, bt); + + if (!IS_KVADDR(req->pc)) { + done = TRUE; + break; + } + + alpha_frame_offset(req, 0); + if (!req->value) { + done = TRUE; + break; + } + + frame++; + alpha_print_stack_entry(req, + req->pc, closest_symbol(req->pc), + bt->flags | BT_SAVE_LASTSP, bt); + + if (BT_REFERENCE_FOUND(bt)) + return; + + if (!IS_KVADDR(req->pc)) { + done = TRUE; + break; + } + + req->prevpc = req->pc; + req->pc = GET_STACK_ULONG(req->sp); + req->prevsp = req->sp; + req->sp += req->value; + break; + + case ALPHA_SYSCALL_FRAME: + req->sp = verify_user_eframe(bt, req->task, req->sp) ? + req->sp : USER_EFRAME_ADDR(req->task); + + alpha_exception_frame(req->sp, bt->flags, req, bt); + + if (!IS_KVADDR(req->pc)) { + done = TRUE; + break; + } + + alpha_frame_offset(req, 0); + if (!req->value) { + done = TRUE; + break; + } + req->prevpc = req->pc; + req->pc = GET_STACK_ULONG(req->sp); + req->prevsp = req->sp; + req->sp += req->value; + break; + + case ALPHA_SIGNAL_RETURN: + alpha_exception_frame(USER_EFRAME_ADDR(req->task), + bt->flags, req, bt); + done = TRUE; + break; + + case ALPHA_EXCEPTION_FRAME: + alpha_frame_offset(req, 0); + if (!req->value) { + fprintf(fp, + "ALPHA EXCEPTION FRAME w/no frame offset for %lx (%s)\n", + req->pc, + value_to_symstr(req->pc, buf, 0)); + done = TRUE; + break; + } + + alpha_exception_frame(req->sp + req->value, + bt->flags, req, bt); + + if (!IS_KVADDR(req->pc)) { + done = TRUE; + break; + } + + alpha_frame_offset(req, 0); + + if (!req->value) { + fprintf(fp, + "ALPHA EXCEPTION FRAME w/no frame offset for %lx (%s)\n", + req->pc, + value_to_symstr(req->pc, buf, 0)); + done = TRUE; + break; + } + + eframe_same_pc_ra_function = + SAME_FUNCTION(req->pc, req->ra); + + frame++; + alpha_print_stack_entry(req, req->pc, + closest_symbol(req->pc), + bt->flags | BT_SAVE_LASTSP, bt); + + if (BT_REFERENCE_FOUND(bt)) + return; + + if (!IS_KVADDR(req->pc)) { + done = TRUE; + break; + } + + if (STREQ(closest_symbol(req->pc), + "ret_from_reschedule")) { + alpha_exception_frame( + USER_EFRAME_ADDR(req->task), + BT_USER_EFRAME|BT_RESCHEDULE, req, bt); + done = TRUE; + break; + } + + req->prevpc = req->pc; + req->pc = GET_STACK_ULONG(req->sp); + + if (!is_kernel_text(req->pc)) { + if (alpha_backtrace_resync(req, + bt->flags | BT_FROM_EXCEPTION, bt)) + break; + + if (BT_REFERENCE_FOUND(bt)) + return; + + ALPHA_BACKTRACE_SPECULATE(3); + } + + if (!eframe_same_pc_ra_function && + (req->pc != req->ra)) { + req->pc = req->ra; + break; + } + + req->prevsp = req->sp; + req->sp += req->value; + break; + + case ALPHA_INTERRUPT_PENDING: + alpha_frame_offset(req, 0); + if (!req->value) { + req->prevpc = req->pc; + req->pc = req->addr; + req->prevsp = req->sp; + req->sp = req->frame; + } else { + req->prevpc = req->pc; + req->pc = GET_STACK_ULONG(req->sp); + req->prevsp = req->sp; + req->sp += req->value; + } + break; + } + } + + return; + +show_remaining_text: + + if (BT_REFERENCE_CHECK(bt)) + return; + + BZERO(btloc, sizeof(struct bt_info)); + btloc->task = req->task; + btloc->tc = bt->tc; + btloc->stackbase = bt->stackbase; + btloc->stacktop = bt->stacktop; + btloc->flags = BT_TEXT_SYMBOLS_NOPRINT; + hook.esp = req->lastsp + sizeof(long); + btloc->hp = &hook; + back_trace(btloc); + + if (hook.eip) { + fprintf(fp, +"NOTE: cannot resolve trace from this point -- remaining text symbols on stack:\n"); + btloc->flags = BT_TEXT_SYMBOLS_PRINT|BT_ERROR_MASK; + hook.esp = req->lastsp + sizeof(long); + back_trace(btloc); + } else + fprintf(fp, +"NOTE: cannot resolve trace from this point -- no remaining text symbols\n"); + + if (CRASHDEBUG(1)) + fprintf(fp, "speculate_location: %d\n", speculate_location); + + alpha_exception_frame(USER_EFRAME_ADDR(req->task), + BT_USER_EFRAME, req, bt); +} + +/* + * print one entry of a stack trace + */ +static void +alpha_print_stack_entry(struct gnu_request *req, + ulong callpc, + char *name, + ulong flags, + struct bt_info *bt) +{ + struct load_module *lm; + + if (BT_REFERENCE_CHECK(bt)) { + switch (bt->ref->cmdflags & (BT_REF_SYMBOL|BT_REF_HEXVAL)) + { + case BT_REF_SYMBOL: + if (STREQ(name, bt->ref->str) || + (STREQ(name, "strace") && + STREQ(bt->ref->str, "entSys"))) { + bt->ref->cmdflags |= BT_REF_FOUND; + } + break; + + case BT_REF_HEXVAL: + if (bt->ref->hexval == callpc) + bt->ref->cmdflags |= BT_REF_FOUND; + break; + } + } else { + fprintf(fp, "%s#%d [%lx] %s at %lx", + req->curframe < 10 ? " " : "", req->curframe, req->sp, + STREQ(name, "strace") ? "strace (via entSys)" : name, + callpc); + if (module_symbol(callpc, NULL, &lm, NULL, 0)) + fprintf(fp, " [%s]", lm->mod_name); + fprintf(fp, "\n"); + } + + if (!(flags & BT_SPECULATE)) + req->curframe++; + + if (flags & BT_SAVE_LASTSP) + req->lastsp = req->sp; + + if (BT_REFERENCE_CHECK(bt)) + return; + + if (flags & BT_LINE_NUMBERS) + alpha_dump_line_number(name, callpc); +} + +static const char *hook_files[] = { + "arch/alpha/kernel/entry.S", + "arch/alpha/kernel/head.S", + "init/main.c", + "arch/alpha/kernel/smp.c", +}; + +#define ENTRY_S ((char **)&hook_files[0]) +#define HEAD_S ((char **)&hook_files[1]) +#define MAIN_C ((char **)&hook_files[2]) +#define SMP_C ((char **)&hook_files[3]) + +static struct line_number_hook alpha_line_number_hooks[] = { + {"entInt", ENTRY_S}, + {"entMM", ENTRY_S}, + {"entArith", ENTRY_S}, + {"entIF", ENTRY_S}, + {"entDbg", ENTRY_S}, + {"kernel_clone", ENTRY_S}, + {"kernel_thread", ENTRY_S}, + {"__kernel_execve", ENTRY_S}, + {"do_switch_stack", ENTRY_S}, + {"undo_switch_stack", ENTRY_S}, + {"entUna", ENTRY_S}, + {"entUnaUser", ENTRY_S}, + {"sys_fork", ENTRY_S}, + {"sys_clone", ENTRY_S}, + {"sys_vfork", ENTRY_S}, + {"alpha_switch_to", ENTRY_S}, + {"entSys", ENTRY_S}, + {"ret_from_sys_call", ENTRY_S}, + {"ret_from_reschedule", ENTRY_S}, + {"restore_all", ENTRY_S}, + {"strace", ENTRY_S}, + {"strace_success", ENTRY_S}, + {"strace_error", ENTRY_S}, + {"syscall_error", ENTRY_S}, + {"ret_success", ENTRY_S}, + {"signal_return", ENTRY_S}, + {"ret_from_fork", ENTRY_S}, + {"reschedule", ENTRY_S}, + {"sys_sigreturn", ENTRY_S}, + {"sys_rt_sigreturn", ENTRY_S}, + {"sys_sigsuspend", ENTRY_S}, + {"sys_rt_sigsuspend", ENTRY_S}, + {"ret_from_smpfork", ENTRY_S}, + + {"_stext", HEAD_S}, + {"__start", HEAD_S}, + {"__smp_callin", HEAD_S}, + {"cserve_ena", HEAD_S}, + {"cserve_dis", HEAD_S}, + {"halt", HEAD_S}, + + {"start_kernel", MAIN_C}, + + {"smp_callin", SMP_C}, + + {NULL, NULL} /* list must be NULL-terminated */ +}; + +static void +alpha_dump_line_number(char *name, ulong callpc) +{ + char buf[BUFSIZE], *p; + int retries; + + retries = 0; +try_closest: + get_line_number(callpc, buf, FALSE); + if (strlen(buf)) { + if (retries) { + p = strstr(buf, ": "); + if (p) + *p = NULLCHAR; + } + fprintf(fp, " %s\n", buf); + } else { + if (retries) + fprintf(fp, GDB_PATCHED() ? + "" : " (cannot determine file and line number)\n"); + else { + retries++; + callpc = closest_symbol_value(callpc); + goto try_closest; + } + } +} + + +/* + * Look for the frame size storage at the beginning of a function. + * If it's not obvious, try gdb. + * + * For future reference, here's where the numbers come from: + * + * 0xfffffc00003217e8 : subq sp,0x50,sp + * fffffc00003217e8: 43ca153e + * 010000 11110 01010000 1 0101001 11110 + * + * 0xfffffc0000321668 : subq sp,0x60,sp + * fffffc0000321668: 43cc153e + * 010000 11110 01100000 1 0101001 11110 + * + * 0xfffffc000035d028 : subq sp,0x70,sp + * fffffc000035d028: 43ce153e + * 010000 11110 01110000 1 0101001 11110 + * + * 0100 0011 110x xxxx xxx1 0101 0011 1110 + * 1111 1111 111x xxxx xxx1 1111 1111 1111 + * 0000 0000 0001 1111 1110 0000 0000 0000 + * f f e 0 1 f f f instruction mask + * 0 0 1 f e 0 0 0 offset + * + * stq ra,0(sp) + * fffffc000035d034: b75e0000 + */ + +static void +alpha_frame_offset(struct gnu_request *req, ulong alt_pc) +{ + uint *ip, ival; + ulong value; + + req->value = value = 0; + + if (alt_pc && !is_kernel_text(alt_pc)) + error(FATAL, + "trying to get frame offset of non-text address: %lx\n", + alt_pc); + else if (!alt_pc && !is_kernel_text(req->pc)) + error(FATAL, + "trying to get frame offset of non-text address: %lx\n", + req->pc); + + ip = alt_pc ? (int *)closest_symbol_value(alt_pc) : + (int *)closest_symbol_value(req->pc); + if (!ip) + goto use_gdb; + + ival = 0; + + /* + * Don't go any farther than "stq ra,0(sp)" (0xb75e0000) + */ + while (ival != 0xb75e0000) { + if (!text_value_cache((ulong)ip, 0, &ival)) { + readmem((ulong)ip, KVADDR, &ival, + sizeof(uint), "uncached text value", + FAULT_ON_ERROR); + text_value_cache((ulong)ip, ival, NULL); + } + + if ((ival & 0xffe01fff) == 0x43c0153e) { + value = (ival & 0x1fe000) >> 13; + break; + } + ip++; + } + + if (value) { + req->value = value; + return; + } + +use_gdb: +#ifndef GDB_5_3 +{ + static int gdb_frame_offset_warnings = 10; + + if (gdb_frame_offset_warnings-- > 0) + error(WARNING, + "GNU_ALPHA_FRAME_OFFSET functionality not ported to gdb\n"); +} +#endif + req->command = GNU_ALPHA_FRAME_OFFSET; + if (alt_pc) { + ulong pc_save; + pc_save = req->pc; + req->pc = alt_pc; + gdb_interface(req); + req->pc = pc_save; + } else + gdb_interface(req); +} + +/* + * Look for key routines that either mean the trace has ended or has + * bumped into an exception frame. + */ +int +alpha_trace_status(struct gnu_request *req, struct bt_info *bt) +{ + ulong value; + char *func; + ulong frame; + + req->addr = 0; + func = req->name; + frame = req->sp; + + if (STREQ(func, "start_kernel") || + STREQ(func, "smp_callin") || + STREQ(func, "kernel_thread") || + STREQ(func, "__kernel_thread")) + return ALPHA_END_OF_TRACE; + + if (STREQ(func, "ret_from_smp_fork") || + STREQ(func, "ret_from_smpfork")) + return ALPHA_RET_FROM_SMP_FORK; + + if (STREQ(func, "entSys")) + return ALPHA_SYSCALL_FRAME; + + if (STREQ(func, "entMM")) { + req->sp += 56; /* see entMM in entry.S */ + return ALPHA_MM_FAULT; + } + + if (STREQ(func, "do_entInt")) + return ALPHA_EXCEPTION_FRAME; + + if (STREQ(func, "do_entArith")) + return ALPHA_EXCEPTION_FRAME; + + if (STREQ(func, "do_entIF")) + return ALPHA_EXCEPTION_FRAME; + + if (STREQ(func, "do_entDbg")) + return ALPHA_EXCEPTION_FRAME; + + if (STREQ(func, "handle_bottom_half")) + return ALPHA_EXCEPTION_FRAME; + + if (STREQ(func, "handle_softirq")) + return ALPHA_EXCEPTION_FRAME; + + if (STREQ(func, "reschedule")) + return ALPHA_RESCHEDULE; + + if (STREQ(func, "ret_from_reschedule")) + return ALPHA_RESCHEDULE; + + if (STREQ(func, "signal_return")) + return ALPHA_SIGNAL_RETURN; + + if (STREQ(func, "strace")) + return ALPHA_STRACE; + + if (STREQ(func, "__down_failed") || + STREQ(func, "__down_failed_interruptible")) { + readmem(req->sp + 144, KVADDR, &req->pc, sizeof(ulong), + "__down_failed r26", FAULT_ON_ERROR); + req->sp += 160; + return ALPHA_DOWN_FAILED; + } + + value = GET_STACK_ULONG(frame); + + if (STREQ(closest_symbol(value), "do_entInt") || + STREQ(closest_symbol(value), "do_entArith") || + STREQ(closest_symbol(value), "do_entIF") || + STREQ(closest_symbol(value), "do_entDbg")) { + req->addr = value; + req->frame = 0; + + while (INSTACK(frame, bt)) { + frame += sizeof(ulong); + value = GET_STACK_ULONG(frame); + if (STREQ(closest_symbol(value), "ret_from_sys_call")) { + alpha_frame_offset(req, req->addr); + /* req->frame = frame + req->value; XXX */ + break; + } + } + return ALPHA_INTERRUPT_PENDING; + } + + return ALPHA_CONTINUE_TRACE; +} + +/* + * Redo the gdb pt_regs structure output. + */ +enum regnames { _r0_, _r1_, _r2_, _r3_, _r4_, _r5_, _r6_, _r7_, _r8_, + _r19_, _r20_, _r21_, _r22_, _r23_, _r24_, _r25_, _r26_, + _r27_, _r28_, _hae_, _trap_a0_, _trap_a1_, _trap_a2_, + _ps_, _pc_, _gp_, _r16_, _r17_, _r18_, NUMREGS}; + +struct alpha_eframe { + char regs[30][30]; + ulong value[29]; +}; + +static void +alpha_exception_frame(ulong addr, + ulong flags, + struct gnu_request *req, + struct bt_info *bt) +{ + int i, j; + char buf[BUFSIZE]; + ulong value; + physaddr_t paddr; + struct alpha_eframe eframe; + + if (CRASHDEBUG(4)) + fprintf(fp, "alpha_exception_frame: %lx\n", addr); + + if (flags & BT_SPECULATE) { + req->pc = 0; + fprintf(fp, "ALPHA EXCEPTION FRAME\n"); + return; + } + + BZERO(&eframe, sizeof(struct alpha_eframe)); + + open_tmpfile(); + dump_struct("pt_regs", addr, RADIX(16)); + rewind(pc->tmpfile); + while (fgets(buf, BUFSIZE, pc->tmpfile)) { + strip_comma(clean_line(buf)); + if (!strstr(buf, "0x")) + continue; + + extract_hex(buf, &value, NULLCHAR, TRUE); + if (CRASHDEBUG(4)) + fprintf(pc->saved_fp, "<%s> %lx\n", buf, value); + + if (STRNEQ(buf, "r0 = ")) { + sprintf(eframe.regs[_r0_], " V0/R0: %016lx", value); + eframe.value[_r0_] = value; + } + if (STRNEQ(buf, "r1 = ")) { + sprintf(eframe.regs[_r1_], " T0/R1: %016lx", value); + eframe.value[_r1_] = value; + } + if (STRNEQ(buf, "r2 = ")) { + sprintf(eframe.regs[_r2_], " T1/R2: %016lx", value); + eframe.value[_r2_] = value; + } + if (STRNEQ(buf, "r3 = ")) { + sprintf(eframe.regs[_r3_], " T2/R3: %016lx", value); + eframe.value[_r3_] = value; + } + if (STRNEQ(buf, "r4 = ")) { + sprintf(eframe.regs[_r4_], " T3/R4: %016lx", value); + eframe.value[_r4_] = value; + } + if (STRNEQ(buf, "r5 = ")) { + sprintf(eframe.regs[_r5_], " T4/R5: %016lx", value); + eframe.value[_r5_] = value; + } + if (STRNEQ(buf, "r6 = ")) { + sprintf(eframe.regs[_r6_], " T5/R6: %016lx", value); + eframe.value[_r6_] = value; + } + if (STRNEQ(buf, "r7 = ")) { + sprintf(eframe.regs[_r7_], " T6/R7: %016lx", value); + eframe.value[_r7_] = value; + } + if (STRNEQ(buf, "r8 = ")) { + sprintf(eframe.regs[_r8_], " T7/R8: %016lx", value); + eframe.value[_r8_] = value; + } + if (STRNEQ(buf, "r19 = ")) { + sprintf(eframe.regs[_r19_], " A3/R19: %016lx", value); + eframe.value[_r19_] = value; + } + if (STRNEQ(buf, "r20 = ")) { + sprintf(eframe.regs[_r20_], " A4/R20: %016lx", value); + eframe.value[_r20_] = value; + } + if (STRNEQ(buf, "r21 = ")) { + sprintf(eframe.regs[_r21_], " A5/R21: %016lx", value); + eframe.value[_r21_] = value; + } + if (STRNEQ(buf, "r22 = ")) { + sprintf(eframe.regs[_r22_], " T8/R22: %016lx", value); + eframe.value[_r22_] = value; + } + if (STRNEQ(buf, "r23 = ")) { + sprintf(eframe.regs[_r23_], " T9/R23: %016lx", value); + eframe.value[_r23_] = value; + } + if (STRNEQ(buf, "r24 = ")) { + sprintf(eframe.regs[_r24_], "T10/R24: %016lx", value); + eframe.value[_r24_] = value; + } + if (STRNEQ(buf, "r25 = ")) { + sprintf(eframe.regs[_r25_], "T11/R25: %016lx", value); + eframe.value[_r25_] = value; + } + if (STRNEQ(buf, "r26 = ")) { + sprintf(eframe.regs[_r26_], " RA/R26: %016lx", value); + eframe.value[_r26_] = value; + } + if (STRNEQ(buf, "r27 = ")) { + sprintf(eframe.regs[_r27_], "T12/R27: %016lx", value); + eframe.value[_r27_] = value; + } + if (STRNEQ(buf, "r28 = ")) { + sprintf(eframe.regs[_r28_], " AT/R28: %016lx", value); + eframe.value[_r28_] = value; + } + if (STRNEQ(buf, "hae = ")) { + sprintf(eframe.regs[_hae_], " HAE: %016lx", value); + eframe.value[_hae_] = value; + } + if (STRNEQ(buf, "trap_a0 = ")) { + sprintf(eframe.regs[_trap_a0_], "TRAP_A0: %016lx", + value); + eframe.value[_trap_a0_] = value; + } + if (STRNEQ(buf, "trap_a1 = ")) { + sprintf(eframe.regs[_trap_a1_], "TRAP_A1: %016lx", + value); + eframe.value[_trap_a1_] = value; + } + if (STRNEQ(buf, "trap_a2 = ")) { + sprintf(eframe.regs[_trap_a2_], "TRAP_A2: %016lx", + value); + eframe.value[_trap_a2_] = value; + } + if (STRNEQ(buf, "ps = ")) { + sprintf(eframe.regs[_ps_], " PS: %016lx", value); + eframe.value[_ps_] = value; + } + if (STRNEQ(buf, "pc = ")) { + sprintf(eframe.regs[_pc_], " PC: %016lx", value); + eframe.value[_pc_] = value; + } + if (STRNEQ(buf, "gp = ")) { + sprintf(eframe.regs[_gp_], " GP/R29: %016lx", value); + eframe.value[_gp_] = value; + } + if (STRNEQ(buf, "r16 = ")) { + sprintf(eframe.regs[_r16_], " A0/R16: %016lx", value); + eframe.value[_r16_] = value; + } + if (STRNEQ(buf, "r17 = ")) { + sprintf(eframe.regs[_r17_], " A1/R17: %016lx", value); + eframe.value[_r17_] = value; + } + if (STRNEQ(buf, "r18 =")) { + sprintf(eframe.regs[_r18_], " A2/R18: %016lx", value); + eframe.value[_r18_] = value; + } + } + close_tmpfile(); + + if ((flags & BT_EXCEPTION_FRAME) && !BT_REFERENCE_CHECK(bt)) { +dump_eframe: + fprintf(fp, " EFRAME: %lx ", addr); + fprintf(fp, "%s\n", eframe.regs[_r24_]); + + for (i = 0; i < (((NUMREGS+1)/2)-1); i++) { + fprintf(fp, "%s ", eframe.regs[i]); + pad_line(fp, 21 - strlen(eframe.regs[i]), ' '); + j = i+((NUMREGS+1)/2); + fprintf(fp, "%s", eframe.regs[j]); + if (((j == _pc_) || (j == _r26_)) && + is_kernel_text(eframe.value[j])) + fprintf(fp, " <%s>", + value_to_symstr(eframe.value[j], buf, 0)); + fprintf(fp, "\n"); + } + } + + req->ra = eframe.value[_r26_]; + req->pc = eframe.value[_pc_]; + req->sp = addr + (29 * sizeof(ulong)); + + if (flags & BT_USER_EFRAME) { + flags &= ~BT_USER_EFRAME; + if (!BT_REFERENCE_CHECK(bt) && (eframe.value[_ps_] == 8) && + (((uvtop(task_to_context(req->task), req->pc, &paddr, 0) || + (volatile ulong)paddr) && + (uvtop(task_to_context(req->task), req->ra, &paddr, 0) || + (volatile ulong)paddr)) || + (IS_ZOMBIE(req->task) || IS_EXITING(req->task)))) { + if (!(flags & + (BT_RESCHEDULE|BT_RET_FROM_SMP_FORK|BT_STRACE))) + fprintf(fp, + "NOTE: kernel-entry exception frame:\n"); + goto dump_eframe; + } + } +} + +/* + * Look for likely exception frames in a stack. + */ +struct alpha_pt_regs { + ulong reg_value[NUMREGS]; +}; + +static int +alpha_eframe_search(struct bt_info *bt) +{ + ulong *first, *last; + ulong eframe; + struct alpha_pt_regs *pt; + struct gnu_request *req; /* needed for alpha_exception_frame */ + ulong *stack; + int cnt; + + stack = (ulong *)bt->stackbuf; + req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request)); + req->task = bt->task; + + first = stack + + (roundup(SIZE(task_struct), sizeof(ulong)) / sizeof(ulong)); + last = stack + + (((bt->stacktop - bt->stackbase) - SIZE(pt_regs)) / sizeof(ulong)); + + for (cnt = 0; first <= last; first++) { + pt = (struct alpha_pt_regs *)first; + + /* check for kernel exception frame */ + + if (!(pt->reg_value[_ps_] & 0xfffffffffffffff8) && + (is_kernel_text(pt->reg_value[_pc_]) || + IS_MODULE_VADDR(pt->reg_value[_pc_])) && + (is_kernel_text(pt->reg_value[_r26_]) || + IS_MODULE_VADDR(pt->reg_value[_r26_])) && + IS_KVADDR(pt->reg_value[_gp_])) { + cnt++; + if (bt->flags & BT_EFRAME_COUNT) + continue; + fprintf(fp, "\nKERNEL-MODE EXCEPTION FRAME:\n"); + eframe = bt->task + ((ulong)first - (ulong)stack); + alpha_exception_frame(eframe, BT_EXCEPTION_FRAME, + req, bt); + continue; + } + + /* check for user exception frame */ + + if ((pt->reg_value[_ps_] == 0x8) && + ((IN_TASK_VMA(bt->task, pt->reg_value[_pc_]) && + IN_TASK_VMA(bt->task, pt->reg_value[_r26_]) && + IS_UVADDR(pt->reg_value[_gp_], bt->tc)) || + ((first == last) && + (IS_ZOMBIE(bt->task) || IS_EXITING(bt->task))))) { + cnt++; + if (bt->flags & BT_EFRAME_COUNT) + continue; + fprintf(fp, "\nUSER-MODE EXCEPTION FRAME:\n"); + eframe = bt->task + ((ulong)first - (ulong)stack); + alpha_exception_frame(eframe, BT_EXCEPTION_FRAME, + req, bt); + } + } + + FREEBUF(req); + + return cnt; +} + +/* + * Before dumping a nonsensical exception frame, give it a quick test. + */ +static int +verify_user_eframe(struct bt_info *bt, ulong task, ulong sp) +{ + struct alpha_pt_regs ptbuf, *pt; + + readmem(sp, KVADDR, &ptbuf, sizeof(struct alpha_pt_regs), + "pt_regs", FAULT_ON_ERROR); + + pt = &ptbuf; + + if ((pt->reg_value[_ps_] == 0x8) && + ((IN_TASK_VMA(task, pt->reg_value[_pc_]) && + IN_TASK_VMA(task, pt->reg_value[_r26_]) && + IS_UVADDR(pt->reg_value[_gp_], bt->tc)) || + ((pt == (struct alpha_pt_regs *)USER_EFRAME_ADDR(task)) && + (IS_ZOMBIE(task) || IS_EXITING(task))))) { + return TRUE; + } + + return FALSE; +} + +/* + * Try to resync the stack location when there is no valid stack frame, + * typically just above an exception frame. Use the req->ra value from the + * exception frame as the new starting req->pc. Then walk up the stack until + * a text routine that calls the newly-assigned pc is found -- that stack + * location then becomes the new req->sp. + * + * If we're not coming from an exception frame, req-ra and req->pc will be + * purposely zeroed out. In that case, use the prevsp value to find the + * first pc that called the last frame's pc. + * + * Add any other repeatable "special-case" frames to the beginning of this + * routine (ex. debug_spin_lock). Last ditch -- at the end of this routine, + * speculate what might have happened (possibly in the background) -- and + * if it looks good, run with it. + */ +static int +alpha_backtrace_resync(struct gnu_request *req, ulong flags, struct bt_info *bt) +{ + char addr[BUFSIZE]; + char buf[BUFSIZE]; + char lookfor1[BUFSIZE]; + char lookfor2[BUFSIZE]; + ulong newpc; + ulong *stkp; + ulong *stkp_newpc, *stkp_next; + ulong value; + int found; + char *name; + int exception; + + if (CRASHDEBUG(1)) + fprintf(fp, + "RESYNC1: [%lx-%d] ra: %lx pc: %lx sp: %lx\n", + flags, req->curframe, req->ra, req->pc, req->sp); + + if (!req->ra && !req->pc) { + req->ra = req->prevpc; + exception = FALSE; + } else + exception = TRUE; + + if (!IS_KVADDR(req->ra)) + return FALSE; + + name = closest_symbol(req->ra); + sprintf(lookfor1, "<%s>", name); + sprintf(lookfor2, "<%s+", name); + + if (CRASHDEBUG(1)) + fprintf(fp, "RESYNC2: exception: %s lookfor: %s or %s\n", + exception ? "TRUE" : "FALSE", + lookfor1, lookfor2); + + /* + * This is common when a non-panicking active CPU is spinning + * in debug_spin_lock(). The next pc is offset by 0x30 from + * the top of the exception frame, and the next sp is equal + * to the frame offset of debug_spin_lock(). I can't explain it... + */ + if ((flags & BT_FROM_EXCEPTION) && STREQ(name, "debug_spin_lock")) { + alpha_print_stack_entry(req, req->ra, + closest_symbol(req->ra), flags, bt); + + if (BT_REFERENCE_FOUND(bt)) + return FALSE; + + alpha_frame_offset(req, req->ra); + stkp = (ulong *)(req->sp + 0x30); + value = GET_STACK_ULONG(stkp); + if (!is_kernel_text(value)) { + req->sp = req->prevsp; + return FALSE; + } + req->pc = value; + req->sp += req->value; + return TRUE; + } + + /* + * If the ra is a system call, then all we should have to do is + * find the next reference to entSys on the stack, and set the + * sp to that value. + */ + if (is_system_call(name, 0)) { + /* stkp = (ulong *)req->sp; */ + stkp = (ulong *)req->prevsp; + + for (stkp++; INSTACK(stkp, bt); stkp++) { + value = GET_STACK_ULONG(stkp); + + if (IS_KVADDR(value) && is_kernel_text(value)) { + if (STREQ(closest_symbol(value), "entSys")) { + req->pc = value; + req->sp = USER_EFRAME_ADDR(req->task); + return TRUE; + } + } + } + } + + /* + * Just find the next location containing text. (?) + */ + if (STREQ(name, "do_coredump")) { + stkp = (ulong *)(req->sp + sizeof(long)); + for (stkp++; INSTACK(stkp, bt); stkp++) { + value = GET_STACK_ULONG(stkp); + + if (IS_KVADDR(value) && is_kernel_text(value)) { + req->pc = req->ra; + req->sp = (ulong)stkp; + return TRUE; + } + } + } + + if (flags & BT_SPECULATE) + return FALSE; + + if (CRASHDEBUG(1)) { + fprintf(fp, "RESYNC3: prevsp: %lx ra: %lx name: %s\n", + req->prevsp, req->ra, name); + fprintf(fp, "RESYNC3: prevpc: %lx\n", req->prevpc); + } + + stkp_newpc = stkp_next = 0; + newpc = 0; + found = FALSE; + if (exception) { + newpc = req->ra; + stkp = (ulong *)req->sp; + } else + stkp = (ulong *)req->prevsp; + + if (CRASHDEBUG(1)) + fprintf(fp, "RESYNC4: stkp: %lx newpc: %lx\n", + (ulong)stkp, newpc); + + for (stkp++; INSTACK(stkp, bt); stkp++) { + value = GET_STACK_ULONG(stkp); + /* + * First find the new pc on the stack. + */ + if (!found) { + if (!exception && is_kernel_text(value)) { + found = TRUE; + } else if (value == newpc) { + found = TRUE; + stkp_newpc = stkp; + continue; + } + } + + if (!IS_KVADDR(value)) + continue; + + if (is_kernel_text(value)) { + if (!stkp_next) + stkp_next = stkp; + if (CRASHDEBUG(2)) { + fprintf(fp, + "RESYNC6: disassemble %lx (%s)\n", + value - sizeof(uint), + value_to_symstr(value - sizeof(uint), + buf, 0)); + } + req->command = GNU_DISASSEMBLE; + req->addr = value - sizeof(uint); + sprintf(addr, "0x%lx", req->addr); + open_tmpfile(); + req->fp = pc->tmpfile; + gdb_interface(req); + rewind(pc->tmpfile); + while (fgets(buf, BUFSIZE, pc->tmpfile)) { + clean_line(buf); + if (STRNEQ(buf, "Dump of") || + STRNEQ(buf, "End of")) + continue; + + if (STRNEQ(buf, addr)) { + if (LASTCHAR(buf) == ':') { + fgets(buf, BUFSIZE, + pc->tmpfile); + clean_line(buf); + } + if (CRASHDEBUG(2) && + (strstr(buf, "jsr") + || strstr(buf, "bsr"))) + fprintf(pc->saved_fp, "%s\n", + buf); + if ((strstr(buf, "jsr") || + strstr(buf, "bsr")) && + (strstr(buf, lookfor1) || + strstr(buf, lookfor2))) { + if (exception) { + req->pc = newpc; + req->sp = (ulong)stkp; + } else + req->pc = req->addr; + close_tmpfile(); + return TRUE; + } + } + } + close_tmpfile(); + } + } + + if (CRASHDEBUG(1)) { + fprintf(fp, "RESYNC9: [%d] name: %s pc: %lx ra: %lx\n", + req->curframe, name, req->pc, req->ra); + fprintf(fp, "RESYNC9: sp: %lx lastsp: %lx\n", + req->sp, req->lastsp); + fprintf(fp, "RESYNC9: prevpc: %lx prevsp: %lx\n", + req->prevpc, req->prevsp); + } + + /* + * At this point, all we can do is speculate based upon + * past experiences... + */ + return (alpha_resync_speculate(req, flags, bt)); +} + +/* + * Try one level of speculation. If it works, fine -- if not, give up. + */ +static int +alpha_resync_speculate(struct gnu_request *req, ulong flags, struct bt_info *bt) +{ + ulong *stkp; + ulong value; + ulong found_sp, found_ra; + struct stack_hook hook; + struct bt_info bt_info, *btloc; + char buf[BUFSIZE]; + int kernel_thread; + int looks_good; + + if (flags & BT_SPECULATE) /* already been here on this trace... */ + return FALSE; + + if (pc->tmpfile) + return FALSE; + + found_ra = found_sp = 0; + kernel_thread = is_kernel_thread(req->task); + + /* + * Add "known" possibilities here. + */ + switch (flags & (BT_FROM_EXCEPTION|BT_FROM_CALLFRAME)) + { + case BT_FROM_EXCEPTION: + if (STREQ(closest_symbol(req->prevpc), "read_lock") || + STREQ(closest_symbol(req->ra), "do_select") || + STREQ(closest_symbol(req->ra), "schedule")) { + stkp = (ulong *)req->sp; + for (stkp++; INSTACK(stkp, bt); stkp++) { + value = GET_STACK_ULONG(stkp); + + if (found_ra) { + if (is_kernel_text_offset(value)) { + found_sp = (ulong)stkp; + break; + } + continue; + } + + if (value == req->ra) + found_ra = value; + } + } + break; + + case BT_FROM_CALLFRAME: + if (STREQ(closest_symbol(req->ra), "sys_read")) { + value = GET_STACK_ULONG(req->prevsp - 32); + if (STREQ(closest_symbol(value), "entSys")) { + found_ra = value; + found_sp = req->prevsp - 32; + } + } else if (STREQ(closest_symbol(req->ra), "exit_autofs4_fs")) { + stkp = (ulong *)req->sp; + for (stkp++; INSTACK(stkp, bt); stkp++) { + value = GET_STACK_ULONG(stkp); + + if (found_ra && (value != found_ra)) { + if (is_kernel_text_offset(value)) { + found_sp = (ulong)stkp; + break; + } + continue; + } + + if (is_kernel_text_offset(value)) + found_ra = value; + } + } + + break; + + default: + if (req->hookp && + STREQ(closest_symbol(req->prevpc), "filemap_nopage") && + !STREQ(closest_symbol(req->hookp->eip), "do_no_page")) { + found_ra = found_sp = 0; + stkp = (ulong *)req->prevsp; + for (stkp++; INSTACK(stkp, bt); stkp++) { + value = GET_STACK_ULONG(stkp); + + if (found_ra && (value != found_ra)) { + if (is_kernel_text_offset(value)) { + found_sp = (ulong)stkp; + break; + } + continue; + } + + if (is_kernel_text_offset(value) && + STREQ(closest_symbol(value), "do_no_page")) + found_ra = value; + } + if (found_ra && found_sp) { + req->hookp->eip = found_ra; + req->hookp->esp = found_sp; + return TRUE; + } + } + + if (req->hookp) { + found_ra = req->hookp->eip; + found_sp = req->hookp->esp; + } + + break; + } + + if (found_ra && found_sp) { + looks_good = FALSE; + hook.esp = found_sp; + hook.eip = found_ra; + + if (CRASHDEBUG(1)) + fprintf(pc->saved_fp, + "----- RESYNC SPECULATE START -----\n"); + + open_tmpfile(); + btloc = &bt_info; + BZERO(btloc, sizeof(struct bt_info)); + btloc->task = req->task; + btloc->tc = bt->tc; + btloc->stackbase = bt->stackbase; + btloc->stacktop = bt->stacktop; + btloc->flags = BT_SPECULATE; + btloc->hp = &hook; + back_trace(btloc); + rewind(pc->tmpfile); + while (fgets(buf, BUFSIZE, pc->tmpfile)) { + if (CRASHDEBUG(1)) + fprintf(pc->saved_fp, "%s", buf); + + if (strstr(buf, "NOTE: cannot resolve")) { + looks_good = FALSE; + break; + } + + if (strstr(buf, "ALPHA EXCEPTION FRAME")) { + looks_good = TRUE; + break; + } + + if (kernel_thread) { + if (strstr(buf, " kernel_thread ") || + strstr(buf, " __kernel_thread ") || + strstr(buf, " start_kernel ") || + strstr(buf, " smp_callin ")) { + looks_good = TRUE; + break; + } + } + } + close_tmpfile(); + + if (CRASHDEBUG(1)) + fprintf(pc->saved_fp, + "----- RESYNC SPECULATE DONE ------\n"); + + if (looks_good) { + req->pc = found_ra; + req->sp = found_sp; + return TRUE; + } + } + + return FALSE; +} + +/* + * Translates a user virtual address to its physical address. cmd_vtop() + * sets the verbose flag so that the pte translation gets displayed; all + * other callers quietly accept the translation. + * + * This routine can also take mapped kernel virtual addresses if the -u flag + * was passed to cmd_vtop(). If so, it makes the translation using the + * kernel-memory PGD entry instead of swapper_pg_dir. + */ + +static int +alpha_uvtop(struct task_context *tc, ulong vaddr, physaddr_t *paddr, int verbose) +{ + ulong mm; + ulong *pgd; + ulong *page_dir; + ulong *page_middle; + ulong *page_table; + ulong pgd_pte; + ulong pmd_pte; + ulong pte; + + if (!tc) + error(FATAL, "current context invalid\n"); + + *paddr = 0; + + if (is_kernel_thread(tc->task) && IS_KVADDR(vaddr)) { + pgd = (ulong *)machdep->get_task_pgd(tc->task); + } else { + if (!tc->mm_struct) + pgd = (ulong *)machdep->get_task_pgd(tc->task); + else { + if ((mm = task_mm(tc->task, TRUE))) + pgd = ULONG_PTR(tt->mm_struct + + OFFSET(mm_struct_pgd)); + else + readmem(tc->mm_struct + OFFSET(mm_struct_pgd), + KVADDR, &pgd, sizeof(long), + "mm_struct pgd", FAULT_ON_ERROR); + } + } + + if (verbose) + fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd); + + page_dir = pgd + ((vaddr >> PGDIR_SHIFT) & (PTRS_PER_PAGE - 1)); + + FILL_PGD(PAGEBASE(pgd), KVADDR, PAGESIZE()); + pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(page_dir)); + + if (verbose) + fprintf(fp, " PGD: %lx => %lx\n", (ulong)page_dir, pgd_pte); + + if (!(pgd_pte & _PAGE_VALID)) + goto no_upage; + + page_middle = (ulong *) + (PTOV((pgd_pte & _PFN_MASK) >> (32-PAGESHIFT()))) + + ((vaddr >> PMD_SHIFT) & (PTRS_PER_PAGE - 1)); + + FILL_PMD(PAGEBASE(page_middle), KVADDR, PAGESIZE()); + pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(page_middle)); + + if (verbose) + fprintf(fp, " PMD: %lx => %lx\n", (ulong)page_middle, pmd_pte); + + if (!(pmd_pte & _PAGE_VALID)) + goto no_upage; + + page_table = (ulong *) + (PTOV((pmd_pte & _PFN_MASK) >> (32-PAGESHIFT()))) + + (BTOP(vaddr) & (PTRS_PER_PAGE - 1)); + + FILL_PTBL(PAGEBASE(page_table), KVADDR, PAGESIZE()); + pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table)); + + if (verbose) + fprintf(fp, " PTE: %lx => %lx\n", (ulong)page_table, pte); + + if (!(pte & (_PAGE_VALID))) { + *paddr = pte; + if (pte && verbose) { + fprintf(fp, "\n"); + alpha_translate_pte(pte, 0, 0); + } + goto no_upage; + } + + *paddr = ((pte & _PFN_MASK) >> (32-PAGESHIFT())) + PAGEOFFSET(vaddr); + + if (verbose) { + fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(*paddr)); + alpha_translate_pte(pte, 0, 0); + } + + return TRUE; + +no_upage: + return FALSE; +} + +/* + * Translates a kernel virtual address to its physical address. cmd_vtop() + * sets the verbose flag so that the pte translation gets displayed; all + * other callers quietly accept the translation. + */ + +static int +alpha_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose) +{ + ulong *pgd; + ulong *page_dir; + ulong *page_middle; + ulong *page_table; + ulong pgd_pte; + ulong pmd_pte; + ulong pte; + + if (!IS_KVADDR(kvaddr)) + return FALSE; + + if (!vt->vmalloc_start) { /* presume KSEG this early */ + *paddr = VTOP(kvaddr); + return TRUE; + } + + if (!IS_VMALLOC_ADDR(kvaddr)) { + *paddr = VTOP(kvaddr); + return TRUE; + } + + pgd = (ulong *)vt->kernel_pgd[0]; + + if (verbose) + fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd); + + page_dir = pgd + ((kvaddr >> PGDIR_SHIFT) & (PTRS_PER_PAGE - 1)); + + FILL_PGD(PAGEBASE(pgd), KVADDR, PAGESIZE()); + pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(page_dir)); + + if (verbose) + fprintf(fp, " PGD: %lx => %lx\n", (ulong)page_dir, pgd_pte); + + if (!(pgd_pte & _PAGE_VALID)) + goto no_kpage; + + page_middle = (ulong *) + (PTOV((pgd_pte & _PFN_MASK) >> (32-PAGESHIFT()))) + + ((kvaddr >> PMD_SHIFT) & (PTRS_PER_PAGE - 1)); + + FILL_PMD(PAGEBASE(page_middle), KVADDR, PAGESIZE()); + pmd_pte = ULONG(machdep->pmd + PAGEOFFSET(page_middle)); + + if (verbose) + fprintf(fp, " PMD: %lx => %lx\n", (ulong)page_middle, pmd_pte); + + if (!(pmd_pte & _PAGE_VALID)) + goto no_kpage; + + page_table = (ulong *) + (PTOV((pmd_pte & _PFN_MASK) >> (32-PAGESHIFT()))) + + (BTOP(kvaddr) & (PTRS_PER_PAGE - 1)); + + FILL_PTBL(PAGEBASE(page_table), KVADDR, PAGESIZE()); + pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table)); + + if (verbose) + fprintf(fp, " PTE: %lx => %lx\n", (ulong)page_table, pte); + + if (!(pte & (_PAGE_VALID))) { + if (pte && verbose) { + fprintf(fp, "\n"); + alpha_translate_pte(pte, 0, 0); + } + goto no_kpage; + } + + *paddr = ((pte & _PFN_MASK) >> (32-PAGESHIFT())) + PAGEOFFSET(kvaddr); + + if (verbose) { + fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(*paddr)); + alpha_translate_pte(pte, 0, 0); + } + + return TRUE; + +no_kpage: + return FALSE; +} + + +/* + * Get the relevant page directory pointer from a task structure. + */ +static ulong +alpha_get_task_pgd(ulong task) +{ + long offset; + ulong ptbr; + + offset = OFFSET_OPTION(task_struct_thread, task_struct_tss); + + offset += OFFSET(thread_struct_ptbr); + + readmem(task + offset, KVADDR, &ptbr, + sizeof(ulong), "task thread ptbr", FAULT_ON_ERROR); + + return(PTOV(PTOB(ptbr))); +} + +/* + * Calculate and return the speed of the processor. + */ +static ulong +alpha_processor_speed(void) +{ + ulong hwrpb; + long offset; + long cycle_freq; + ulong mhz; + + if (machdep->mhz) + return machdep->mhz; + + mhz = 0; + + get_symbol_data("hwrpb", sizeof(void *), &hwrpb); + offset = OFFSET(hwrpb_struct_cycle_freq); + + if (!hwrpb || (offset == -1) || + !readmem(hwrpb+offset, KVADDR, &cycle_freq, + sizeof(ulong), "hwrpb cycle_freq", RETURN_ON_ERROR)) + return (machdep->mhz = mhz); + + mhz = cycle_freq/1000000; + + return (machdep->mhz = mhz); +} + +void +alpha_dump_machdep_table(ulong arg) +{ + int others; + + others = 0; + fprintf(fp, " flags: %lx (", machdep->flags); + if (machdep->flags & HWRESET) + fprintf(fp, "%sHWRESET", others++ ? "|" : ""); + fprintf(fp, ")\n"); + fprintf(fp, " kvbase: %lx\n", machdep->kvbase); + fprintf(fp, " identity_map_base: %lx\n", machdep->identity_map_base); + fprintf(fp, " pagesize: %d\n", machdep->pagesize); + fprintf(fp, " pageshift: %d\n", machdep->pageshift); + fprintf(fp, " pagemask: %llx\n", machdep->pagemask); + fprintf(fp, " pageoffset: %lx\n", machdep->pageoffset); + fprintf(fp, " stacksize: %ld\n", machdep->stacksize); + fprintf(fp, " hz: %d\n", machdep->hz); + fprintf(fp, " mhz: %ld\n", machdep->mhz); + fprintf(fp, " memsize: %ld (0x%lx)\n", + machdep->memsize, machdep->memsize); + fprintf(fp, " bits: %d\n", machdep->bits); + fprintf(fp, " nr_irqs: %d\n", machdep->nr_irqs); + fprintf(fp, " eframe_search: alpha_eframe_search()\n"); + fprintf(fp, " back_trace: alpha_back_trace_cmd()\n"); + fprintf(fp, " processor_speed: alpha_processor_speed()\n"); + fprintf(fp, " uvtop: alpha_uvtop()\n"); + fprintf(fp, " kvtop: alpha_uvtop()\n"); + fprintf(fp, " get_task_pgd: alpha_get_task_pgd()\n"); + if (machdep->dump_irq == generic_dump_irq) + fprintf(fp, " dump_irq: generic_dump_irq()\n"); + else + fprintf(fp, " dump_irq: alpha_dump_irq()\n"); + fprintf(fp, " get_stack_frame: alpha_get_stack_frame()\n"); + fprintf(fp, " get_stackbase: generic_get_stackbase()\n"); + fprintf(fp, " get_stacktop: generic_get_stacktop()\n"); + fprintf(fp, " translate_pte: alpha_translate_pte()\n"); + fprintf(fp, " memory_size: alpha_get_memory_size()\n"); + fprintf(fp, " vmalloc_start: alpha_get_vmalloc_start()\n"); + fprintf(fp, " is_task_addr: alpha_is_task_addr()\n"); + fprintf(fp, " verify_symbol: alpha_verify_symbol()\n"); + fprintf(fp, " dis_filter: alpha_dis_filter()\n"); + fprintf(fp, " cmd_mach: alpha_cmd_mach()\n"); + fprintf(fp, " get_smp_cpus: alpha_get_smp_cpus()\n"); + fprintf(fp, " is_kvaddr: generic_is_kvaddr()\n"); + fprintf(fp, " is_uvaddr: generic_is_uvaddr()\n"); + fprintf(fp, " verify_paddr: generic_verify_paddr()\n"); + fprintf(fp, " init_kernel_pgd: NULL\n"); + fprintf(fp, " value_to_symbol: generic_machdep_value_to_symbol()\n"); + fprintf(fp, " line_number_hooks: alpha_line_number_hooks\n"); + fprintf(fp, " last_pgd_read: %lx\n", machdep->last_pgd_read); + fprintf(fp, " last_pmd_read: %lx\n", machdep->last_pmd_read); + fprintf(fp, " last_ptbl_read: %lx\n", machdep->last_ptbl_read); + fprintf(fp, " pgd: %lx\n", (ulong)machdep->pgd); + fprintf(fp, " pmd: %lx\n", (ulong)machdep->pmd); + fprintf(fp, " ptbl: %lx\n", (ulong)machdep->ptbl); + fprintf(fp, " ptrs_per_pgd: %d\n", machdep->ptrs_per_pgd); + fprintf(fp, " machspec: %lx\n", (ulong)machdep->machspec); +} + +/* + * Fix up jsr's to show the right target. + * + * If a value is passed with no buf, then cmd_dis is fishing for whether + * the GP can be calculated from the first couple of instructions of the + * target routine: + * + * 0xfffffc0000349fa0 : ldah gp,35(t12) + * 0xfffffc0000349fa4 : lda gp,6216(gp) + * + * If a buf pointer is passed, then check whether the t12 register + * is being set up as an offset from gp, then calculate the target address: + * + * 0xfffffc000042c364 : ldq t12,-29336(gp) + * 0xfffffc000042c368 : + * jsr ra,(t12),0xfffffc0000429dc0 + * + * If the next instruction is a jsr ra,(t12), then correct the bracketed + * target address translation. + * + */ + +#define LDAH_GP_T12 (0x27bb0000) +#define LDA_GP_GP (0x23bd0000) +#define LDQ_T12_GP (0xa77d0000) +#define JSR_RA_T12 (0x6b5b0000) + +#define OPCODE_OPERAND_MASK (0xffff0000) +#define OPCODE_MEM_DISP_MASK (0x0000ffff) + +static struct instruction_data { + uint inst[2]; + short mem_disp[2]; + ulong gp; + ulong target; + char *curfunc; +} instruction_data = { {0} }; + +static int +alpha_dis_filter(ulong vaddr, char *buf, unsigned int output_radix) +{ + struct syment *sp; + struct instruction_data *id; + char buf2[BUFSIZE], *p1; + + id = &instruction_data; + + if (!buf) { + BZERO(id, sizeof(struct instruction_data)); + + if (!(sp = value_search(vaddr, NULL))) + return FALSE; + + readmem(sp->value, KVADDR, &id->inst[0], + sizeof(uint) * 2, "two instructions", FAULT_ON_ERROR); + + if (((id->inst[0] & OPCODE_OPERAND_MASK) == LDAH_GP_T12) && + ((id->inst[1] & OPCODE_OPERAND_MASK) == LDA_GP_GP)) { + id->mem_disp[0] = (short)(id->inst[0] & + OPCODE_MEM_DISP_MASK); + id->mem_disp[1] = (short)(id->inst[1] & + OPCODE_MEM_DISP_MASK); + id->gp = sp->value + (65536*id->mem_disp[0]) + + id->mem_disp[1]; + id->curfunc = sp->name; + + if (CRASHDEBUG(1)) + console("%s: ldah(%d) and lda(%d) gp: %lx\n", + id->curfunc, + id->mem_disp[0], id->mem_disp[1], + id->gp); + + return TRUE; + } + /* send all lines through the generic */ + return TRUE; /* dis_address_translation() filter */ + } + + dis_address_translation(vaddr, buf, output_radix); + + if (!id->gp || !(sp = value_search(vaddr, NULL)) || + !STREQ(id->curfunc, sp->name)) { + BZERO(id, sizeof(struct instruction_data)); + return FALSE; + } + + readmem(vaddr, KVADDR, &id->inst[0], + sizeof(uint), "one instruction", FAULT_ON_ERROR); + + if ((id->inst[0] & OPCODE_OPERAND_MASK) == JSR_RA_T12) { + + if (!id->target || !strstr(buf, "jsr\tra,(t12)") || + !strstr(buf, "<")) + return FALSE; + + p1 = strstr(strstr(buf, "jsr"), "0x"); + sprintf(p1, "0x%lx <%s>%s", + id->target, + value_to_symstr(id->target, buf2, output_radix), + CRASHDEBUG(1) ? " [PATCHED]\n" : "\n"); + return TRUE; + } + + if ((id->inst[0] & OPCODE_OPERAND_MASK) == LDQ_T12_GP) { + id->mem_disp[0] = (short)(id->inst[0] & OPCODE_MEM_DISP_MASK); + readmem(id->gp + id->mem_disp[0], KVADDR, &id->target, + sizeof(ulong), "jsr target", FAULT_ON_ERROR); + } else + id->target = 0; + + return TRUE; +} + +/* + * For some reason gdb can go off into the weeds translating text addresses, + * so this routine both fixes the references as well as imposing the current + * output radix on the translations. + */ +static void +dis_address_translation(ulong vaddr, char *inbuf, unsigned int output_radix) +{ + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char *colon, *p1; + int argc; + char *argv[MAXARGS]; + ulong value; + + console("IN: %s", inbuf); + + colon = strstr(inbuf, ":"); + + if (colon) { + sprintf(buf1, "0x%lx <%s>", vaddr, + value_to_symstr(vaddr, buf2, output_radix)); + sprintf(buf2, "%s%s", buf1, colon); + strcpy(inbuf, buf2); + } + + strcpy(buf1, inbuf); + argc = parse_line(buf1, argv); + + if ((FIRSTCHAR(argv[argc-1]) == '<') && + (LASTCHAR(argv[argc-1]) == '>')) { + p1 = rindex(inbuf, '<'); + while ((p1 > inbuf) && (*p1 != ',')) + p1--; + + if (!STRNEQ(p1, ",0x")) + return; + p1++; + + if (!extract_hex(p1, &value, NULLCHAR, TRUE)) + return; + + sprintf(buf1, "0x%lx <%s>\n", value, + value_to_symstr(value, buf2, output_radix)); + + sprintf(p1, "%s", buf1); + } + + console(" %s", inbuf); +} + + +/* + * If we're generically-inclined, call generic_dump_irq(). Otherwise + * dump the IRQ table the old-fashioned way. + */ +static void +alpha_dump_irq(int irq) +{ + ulong action; + ulong value; + char *arglist[MAXARGS]; + int argc, others; + char buf[BUFSIZE]; + + if (symbol_exists("irq_desc")) { + machdep->dump_irq = generic_dump_irq; + return(generic_dump_irq(irq)); + } + + action = symbol_value("irq_action") + (sizeof(void *) * irq); + + readmem(action, KVADDR, &action, + sizeof(void *), "irq_action pointer", FAULT_ON_ERROR); + + if (!action) { + fprintf(fp, " IRQ: %d\n", irq); + fprintf(fp, "handler:\n"); + fprintf(fp, " flags: \n"); + fprintf(fp, " mask: \n"); + fprintf(fp, " name: \n"); + fprintf(fp, " dev_id: \n"); + fprintf(fp, " next: \n\n"); + return; + } + + fprintf(fp, " IRQ: %d\n", irq); + + open_tmpfile(); + +do_linked_action: + dump_struct("irqaction", action, RADIX(16)); + action = 0; + rewind(pc->tmpfile); + while (fgets(buf, BUFSIZE, pc->tmpfile)) { + strip_comma(buf); + argc = parse_line(buf, arglist); + if (STREQ(arglist[0], "struct") || STREQ(buf, "};")) + continue; + + if (STREQ(arglist[0], "handler")) { + fprintf(pc->saved_fp, "handler: %s ", + strip_hex(arglist[2])); + if (argc == 4) + fprintf(pc->saved_fp, "%s", arglist[3]); + fprintf(pc->saved_fp, "\n"); + } + if (STREQ(arglist[0], "flags")) { + value = htol(strip_comma(arglist[2]), + FAULT_ON_ERROR, NULL); + fprintf(pc->saved_fp, + " flags: %lx ", value); + + if (value) { + others = 0; + fprintf(pc->saved_fp, "("); + + if (value & SA_INTERRUPT) + fprintf(pc->saved_fp, + "%sSA_INTERRUPT", + others++ ? "|" : ""); + if (value & SA_PROBE) + fprintf(pc->saved_fp, + "%sSA_PROBE", + others++ ? "|" : ""); + if (value & SA_SAMPLE_RANDOM) + fprintf(pc->saved_fp, + "%sSA_SAMPLE_RANDOM", + others++ ? "|" : ""); + if (value & SA_SHIRQ) + fprintf(pc->saved_fp, + "%sSA_SHIRQ", + others++ ? "|" : ""); + fprintf(pc->saved_fp, ")"); + if (value & ~ACTION_FLAGS) { + fprintf(pc->saved_fp, + " (bits %lx not translated)", + value & ~ACTION_FLAGS); + } + } + + fprintf(pc->saved_fp, "\n"); + + } + if (STREQ(arglist[0], "mask")) { + value = htol(strip_comma(arglist[2]), + FAULT_ON_ERROR, NULL); + fprintf(pc->saved_fp, + " mask: %lx\n", value); + } + if (STREQ(arglist[0], "name")) { + fprintf(pc->saved_fp, " name: %s ", + strip_hex(arglist[2])); + if (argc == 4) + fprintf(pc->saved_fp, "\"%s\"", arglist[3]); + fprintf(pc->saved_fp, "\n"); + } + if (STREQ(arglist[0], "dev_id")) { + value = htol(strip_comma(arglist[2]), + FAULT_ON_ERROR, NULL); + fprintf(pc->saved_fp, + " dev_id: %lx\n", value); + } + if (STREQ(arglist[0], "next")) { + value = htol(strip_comma(arglist[2]), + FAULT_ON_ERROR, NULL); + fprintf(pc->saved_fp, + " next: %s\n", + strip_hex(arglist[2])); + if (value) + action = value; + } + } + close_tmpfile(); + + fprintf(fp, "\n"); + + if (action) + goto do_linked_action; +} + +/* + * Get a stack frame combination of pc and ra from the most relevent spot. + */ +static void +alpha_get_stack_frame(struct bt_info *bt, ulong *pcp, ulong *spp) +{ + struct syment *sp; + ulong ksp; + ulong ip; + + if (pcp) { + if (DUMPFILE() && is_panic_thread(bt->task)) { + sp = next_symbol("crash_save_current_state", NULL); + + if (HWRESET_TASK(bt->task)) + ip = get_percpu_data(0, GET_HALT_PC, 0); + else if (sp) + ip = sp->value - 4; + else + ip = symbol_value("crash_save_current_state") + + 16; + } else + get_alpha_frame(bt, &ip, NULL); + + *pcp = ip; + } + + if (spp) { + ip = 0; + if (!get_panic_ksp(bt, &ksp)) + get_alpha_frame(bt, + HWRESET_TASK(bt->task) ? &ip : NULL, &ksp); + + if (!INSTACK(ksp, bt)) + error(FATAL, + "cannot determine starting stack address\n", + bt->task); + + *spp = ksp; + if (ip) + *pcp = ip; + } +} + +/* + * Do the work formerly done by alpha_get_sp() and alpha_get_pc(). + */ +static void +get_alpha_frame(struct bt_info *bt, ulong *getpc, ulong *getsp) +{ + int i; + ulong ip; + ulong r26; + ulong ksp, sp; + ulong *spp; + ulong percpu_ra; + ulong percpu_pv; + struct percpu_data percpu_data; + char buf[BUFSIZE]; + ulong task; + ulong *stack; + + task = bt->task; + stack = (ulong *)bt->stackbuf; + + if (tt->flags & THREAD_INFO) { /* pcb.ksp is 1st word in thread_info */ + readmem(bt->tc->thread_info, KVADDR, &ksp, sizeof(ulong), + "thread_info pcb ksp", FAULT_ON_ERROR); + sp = ksp; + } else if (VALID_MEMBER(task_struct_tss_ksp)) + ksp = sp = stack[OFFSET(task_struct_tss_ksp)/sizeof(long)]; + else + ksp = sp = stack[OFFSET(task_struct_thread_ksp)/sizeof(long)]; + + ip = 0; + percpu_ra = percpu_pv = 0; + spp = &stack[(sp - task)/sizeof(long)]; + + if (DUMPFILE() && getsp) { + if (HWRESET_TASK(task)) { + if (INSTACK(sp, bt)) { + *getsp = sp; + return; + } else { + get_percpu_data(0, 0, &percpu_data); + percpu_ra = percpu_data.halt_ra; + percpu_pv = percpu_data.halt_pv; + spp = &stack[roundup(SIZE(task_struct), + sizeof(ulong)) / sizeof(ulong)]; + } + } + + if (!percpu_ra && (STREQ(closest_symbol(*spp), "panic") || + STREQ(closest_symbol(*spp), "handle_ipi"))) { + *getsp = sp; + return; + } + } + +percpu_retry: + + if (CRASHDEBUG(1) && percpu_ra) { + fprintf(fp, "get_alpha_frame: look for %lx (%s)\n", + percpu_ra, value_to_symstr(percpu_ra, buf, 0)); + } + + for (i = 0, spp++; spp < &stack[LONGS_PER_STACK]; spp++,i++) { + + if (CRASHDEBUG(1) && (percpu_ra || percpu_pv) && + is_kernel_text(*spp)) { + fprintf(fp, "%lx: %lx (%s)\n", + ((ulong)spp - (ulong)stack) + task, + *spp, value_to_symstr(*spp, buf, 0)); + } + + if (percpu_ra) { + if (*spp == percpu_ra) { + *getsp = ((ulong)spp - (ulong)stack) + task; + return; + } + continue; + } else if (percpu_pv) { + if (*spp == percpu_pv) { + *getsp = ((ulong)spp - (ulong)stack) + task; + if (getpc) + *getpc = percpu_pv; + return; + } + continue; + } + + if (!INSTACK(*spp, bt)) + continue; + + if (is_kernel_text(*(spp+1))) { + sp = *spp; + ip = *(spp+1); + break; + } + } + + if (percpu_ra) { + percpu_ra = 0; + + error(INFO, + "cannot find return address (percpu_ra) in HARDWARE RESET stack\n"); + error(INFO, + "looking for procedure address (percpu_pv) in HARDWARE RESET stack\n"); + + if (CRASHDEBUG(1)) { + fprintf(fp, "get_alpha_frame: look for %lx (%s)\n", + percpu_pv, value_to_symstr(percpu_pv, buf, 0)); + } + spp = &stack[roundup(SIZE(task_struct), + sizeof(ulong)) / sizeof(ulong)]; + + goto percpu_retry; + } + + if (percpu_pv) { + error(INFO, + "cannot find procedure address (percpu_pv) in HARDWARE RESET stack\n"); + } + + /* + * Check for a forked task that has not yet run in user space. + */ + if (!ip) { + if (INSTACK(ksp + OFFSET(switch_stack_r26), bt)) { + readmem(ksp + OFFSET(switch_stack_r26), KVADDR, + &r26, sizeof(ulong), + "ret_from_smp_fork check", FAULT_ON_ERROR); + if (STREQ(closest_symbol(r26), "ret_from_smp_fork") || + STREQ(closest_symbol(r26), "ret_from_smpfork")) { + ip = r26; + sp = ksp; + } + } + + } + + if (getsp) + *getsp = sp; + if (getpc) + *getpc = ip; + +} + +/* + * Fill the percpu_data structure with information from the + * hwrpb/percpu_data structures for a given CPU. If requested, + * return one of the specified entries. + */ +static ulong +get_percpu_data(int cpu, ulong flag, struct percpu_data *pd) +{ + ulong hwrpb, halt_ra, halt_PC, halt_pv; + unsigned long processor_offset, processor_size; + + get_symbol_data("hwrpb", sizeof(void *), &hwrpb); + + readmem(hwrpb+OFFSET(hwrpb_struct_processor_offset), KVADDR, + &processor_offset, sizeof(ulong), + "hwrpb processor_offset", FAULT_ON_ERROR); + + readmem(hwrpb+OFFSET(hwrpb_struct_processor_size), KVADDR, + &processor_size, sizeof(ulong), + "hwrpb processor_size", FAULT_ON_ERROR); + + readmem(hwrpb + processor_offset + (cpu * processor_size) + + OFFSET(percpu_struct_halt_PC), + KVADDR, &halt_PC, sizeof(ulong), + "percpu halt_PC", FAULT_ON_ERROR); + + readmem(hwrpb + processor_offset + (cpu * processor_size) + + OFFSET(percpu_struct_halt_ra), + KVADDR, &halt_ra, sizeof(ulong), + "percpu halt_ra", FAULT_ON_ERROR); + + readmem(hwrpb + processor_offset + (cpu * processor_size) + + OFFSET(percpu_struct_halt_pv), + KVADDR, &halt_pv, sizeof(ulong), + "percpu halt_pv", FAULT_ON_ERROR); + + if (pd) { + pd->halt_PC = halt_PC; + pd->halt_ra = halt_ra; + pd->halt_pv = halt_pv; + } + + switch (flag) + { + case GET_HALT_PC: + return halt_PC; + + case GET_HALT_RA: + return halt_ra; + + case GET_HALT_PV: + return halt_pv; + + default: + return 0; + } +} + +/* + * Translate a PTE, returning TRUE if the page is _PAGE_VALID or _PAGE_PRESENT, + * whichever is appropriate for the machine type. If a physaddr pointer is + * passed in, don't print anything. + */ +static int +alpha_translate_pte(ulong pte, void *physaddr, ulonglong unused) +{ + int c, len1, len2, len3, others, page_present; + char buf[BUFSIZE]; + char buf2[BUFSIZE]; + char buf3[BUFSIZE]; + char ptebuf[BUFSIZE]; + char physbuf[BUFSIZE]; + char *arglist[MAXARGS]; + physaddr_t paddr; + + paddr = PTOB(pte >> 32); + page_present = (pte & _PAGE_VALID); + + if (physaddr) { + *((ulong *)physaddr) = paddr; + return page_present; + } + + sprintf(ptebuf, "%lx", pte); + len1 = MAX(strlen(ptebuf), strlen("PTE")); + fprintf(fp, "%s ", mkstring(buf, len1, CENTER|LJUST, "PTE")); + + if (!page_present && pte) { + swap_location(pte, buf); + if ((c = parse_line(buf, arglist)) != 3) + error(FATAL, "cannot determine swap location\n"); + + len2 = MAX(strlen(arglist[0]), strlen("SWAP")); + len3 = MAX(strlen(arglist[2]), strlen("OFFSET")); + + fprintf(fp, "%s %s\n", + mkstring(buf2, len2, CENTER|LJUST, "SWAP"), + mkstring(buf3, len3, CENTER|LJUST, "OFFSET")); + + strcpy(buf2, arglist[0]); + strcpy(buf3, arglist[2]); + fprintf(fp, "%s %s %s\n", + mkstring(ptebuf, len1, CENTER|RJUST, NULL), + mkstring(buf2, len2, CENTER|RJUST, NULL), + mkstring(buf3, len3, CENTER|RJUST, NULL)); + + return page_present; + } + + sprintf(physbuf, "%llx", paddr); + len2 = MAX(strlen(physbuf), strlen("PHYSICAL")); + fprintf(fp, "%s ", mkstring(buf, len2, CENTER|LJUST, "PHYSICAL")); + + fprintf(fp, "FLAGS\n"); + + fprintf(fp, "%s %s ", + mkstring(ptebuf, len1, CENTER|RJUST, NULL), + mkstring(physbuf, len2, CENTER|RJUST, NULL)); + fprintf(fp, "("); + others = 0; + + if (pte) { + if (pte & _PAGE_VALID) + fprintf(fp, "%sVALID", others++ ? "|" : ""); + if (pte & _PAGE_FOR) + fprintf(fp, "%sFOR", others++ ? "|" : ""); + if (pte & _PAGE_FOW) + fprintf(fp, "%sFOW", others++ ? "|" : ""); + if (pte & _PAGE_FOE) + fprintf(fp, "%sFOE", others++ ? "|" : ""); + if (pte & _PAGE_ASM) + fprintf(fp, "%sASM", others++ ? "|" : ""); + if (pte & _PAGE_KRE) + fprintf(fp, "%sKRE", others++ ? "|" : ""); + if (pte & _PAGE_URE) + fprintf(fp, "%sURE", others++ ? "|" : ""); + if (pte & _PAGE_KWE) + fprintf(fp, "%sKWE", others++ ? "|" : ""); + if (pte & _PAGE_UWE) + fprintf(fp, "%sUWE", others++ ? "|" : ""); + if (pte & _PAGE_DIRTY) + fprintf(fp, "%sDIRTY", others++ ? "|" : ""); + if (pte & _PAGE_ACCESSED) + fprintf(fp, "%sACCESSED", others++ ? "|" : ""); + } else { + fprintf(fp, "no mapping"); + } + + fprintf(fp, ")\n"); + + return page_present; +} + + +/* + * This is currently not machine-dependent, but eventually I'd prefer to use + * the HWPCB for the real physical memory size. + */ +static uint64_t +alpha_memory_size(void) +{ + return (generic_memory_size()); +} + +/* + * Determine where vmalloc'd memory starts. + */ +static ulong +alpha_vmalloc_start(void) +{ + return VMALLOC_START; +} + +/* + * ALPHA tasks are all stacksize-aligned. + */ +static int +alpha_is_task_addr(ulong task) +{ + return (IS_KVADDR(task) && (ALIGNED_STACK_OFFSET(task) == 0)); +} + +/* + * Keep or reject a symbol from the kernel namelist. + */ +int +alpha_verify_symbol(const char *name, ulong value, char type) +{ + if (CRASHDEBUG(8) && name && strlen(name)) + fprintf(fp, "%016lx %s\n", value, name); + + return (name && strlen(name) && (value > MIN_SYMBOL_VALUE)); +} + +/* + * Override smp_num_cpus if possible and necessary. + */ +int +alpha_get_smp_cpus(void) +{ + int cpus; + + if ((cpus = get_cpus_online())) + return cpus; + else + return kt->cpus; +} + +/* + * Machine dependent command. + */ +void +alpha_cmd_mach(void) +{ + int c, cflag; + unsigned int radix; + + cflag = radix = 0; + + while ((c = getopt(argcnt, args, "cxd")) != EOF) { + switch(c) + { + case 'c': + cflag++; + break; + + case 'x': + if (radix == 10) + error(FATAL, + "-d and -x are mutually exclusive\n"); + radix = 16; + break; + + case 'd': + if (radix == 16) + error(FATAL, + "-d and -x are mutually exclusive\n"); + radix = 10; + break; + + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + if (cflag) + display_hwrpb(radix); + else + alpha_display_machine_stats(); +} + +/* + * "mach" command output. + */ +static void +alpha_display_machine_stats(void) +{ + struct new_utsname *uts; + char buf[BUFSIZE]; + ulong mhz; + + uts = &kt->utsname; + + fprintf(fp, " MACHINE TYPE: %s\n", uts->machine); + fprintf(fp, " MEMORY SIZE: %s\n", get_memory_size(buf)); + fprintf(fp, " CPUS: %d\n", kt->cpus); + fprintf(fp, " PROCESSOR SPEED: "); + if ((mhz = machdep->processor_speed())) + fprintf(fp, "%ld Mhz\n", mhz); + else + fprintf(fp, "(unknown)\n"); + fprintf(fp, " HZ: %d\n", machdep->hz); + fprintf(fp, " PAGE SIZE: %d\n", PAGESIZE()); + fprintf(fp, " L1 CACHE SIZE: %d\n", l1_cache_size()); + fprintf(fp, "KERNEL VIRTUAL BASE: %lx\n", machdep->kvbase); + fprintf(fp, "KERNEL VMALLOC BASE: %lx\n", vt->vmalloc_start); + fprintf(fp, " KERNEL STACK SIZE: %ld\n", STACKSIZE()); +} + +/* + * Display the hwrpb_struct and each percpu_struct. + */ +static void +display_hwrpb(unsigned int radix) +{ + int cpu; + ulong hwrpb, percpu; + ulong processor_offset, processor_size; + + get_symbol_data("hwrpb", sizeof(void *), &hwrpb); + + readmem(hwrpb+OFFSET(hwrpb_struct_processor_offset), KVADDR, + &processor_offset, sizeof(ulong), + "hwrpb processor_offset", FAULT_ON_ERROR); + readmem(hwrpb+OFFSET(hwrpb_struct_processor_size), KVADDR, + &processor_size, sizeof(ulong), + "hwrpb processor_size", FAULT_ON_ERROR); + + fprintf(fp, "HWRPB:\n"); + dump_struct("hwrpb_struct", hwrpb, radix); + + for (cpu = 0; cpu < kt->cpus; cpu++) { + fprintf(fp, "\nCPU %d:\n", cpu); + percpu = hwrpb + processor_offset + (processor_size * cpu); + dump_struct("percpu_struct", percpu, radix); + } +} + +/* + * Perform any leftover pre-prompt machine-specific initialization tasks here. + */ +static void +alpha_post_init(void) +{ + modify_signame(7, "SIGEMT", NULL); + modify_signame(10, "SIGBUS", NULL); + modify_signame(12, "SIGSYS", NULL); + modify_signame(16, "SIGURG", NULL); + modify_signame(17, "SIGSTOP", NULL); + modify_signame(18, "SIGTSTP", NULL); + modify_signame(19, "SIGCONT", NULL); + modify_signame(20, "SIGCHLD", NULL); + modify_signame(23, "SIGIO", "SIGPOLL"); + modify_signame(29, "SIGINFO", "SIGPWR"); + modify_signame(30, "SIGUSR1", NULL); + modify_signame(31, "SIGUSR2", NULL); +} + + +#endif /* ALPHA */ diff --git a/arm.c b/arm.c new file mode 100644 index 00000000..3c38cd5d --- /dev/null +++ b/arm.c @@ -0,0 +1,1631 @@ +/* + * arm.c - core analysis suite + * + * Authors: + * Thomas Fänge + * Jan Karlsson + * Mika Westerberg + * + * Copyright (C) 2010-2011 Nokia Corporation + * Copyright (C) 2010 Sony Ericsson. 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. + */ + +#ifdef ARM +#include + +#include "defs.h" + +static void arm_parse_cmdline_args(void); +static int arm_get_crash_notes(void); +static int arm_verify_symbol(const char *, ulong, char); +static int arm_is_module_addr(ulong); +static int arm_is_kvaddr(ulong); +static int arm_is_uvaddr(ulong, struct task_context *); +static int arm_in_exception_text(ulong); +static int arm_in_ret_from_syscall(ulong, int *); +static void arm_back_trace(struct bt_info *); +static void arm_back_trace_cmd(struct bt_info *); +static ulong arm_processor_speed(void); +static int arm_translate_pte(ulong, void *, ulonglong); +static int arm_vtop(ulong, ulong *, physaddr_t *, int); +static int arm_kvtop(struct task_context *, ulong, physaddr_t *, int); +static int arm_uvtop(struct task_context *, ulong, physaddr_t *, int); +static int arm_get_frame(struct bt_info *, ulong *, ulong *); +static int arm_get_dumpfile_stack_frame(struct bt_info *, ulong *, ulong *); +static void arm_get_stack_frame(struct bt_info *, ulong *, ulong *); +static void arm_dump_exception_stack(ulong, ulong); +static void arm_display_full_frame(struct bt_info *, ulong); +static ulong arm_vmalloc_start(void); +static int arm_is_task_addr(ulong); +static int arm_dis_filter(ulong, char *, unsigned int); +static int arm_eframe_search(struct bt_info *); +static ulong arm_get_task_pgd(ulong); +static void arm_cmd_mach(void); +static void arm_display_machine_stats(void); +static int arm_get_smp_cpus(void); +static void arm_init_machspec(void); + +static struct line_number_hook arm_line_number_hooks[]; +static struct machine_specific arm_machine_specific; + +/** + * struct arm_cpu_context_save - idle task registers + * + * This structure holds idle task registers. Only FP, SP, and PC are needed for + * unwinding the stack. + */ +struct arm_cpu_context_save { + ulong fp; + ulong sp; + ulong pc; +}; + +/* + * Holds registers during the crash. + */ +static struct arm_pt_regs *panic_task_regs; + +#define PGDIR_SIZE() (4 * PAGESIZE()) +#define PGDIR_OFFSET(X) (((ulong)(X)) & (PGDIR_SIZE() - 1)) + +#define _SECTION_PAGE_MASK (~((MEGABYTES(1))-1)) + +#define PMD_TYPE_MASK 3 +#define PMD_TYPE_SECT 2 +#define PMD_TYPE_TABLE 1 + +static inline ulong * +pmd_page_addr(ulong pmd) +{ + ulong ptr; + + if (machdep->flags & PGTABLE_V2) { + ptr = PAGEBASE(pmd); + } else { + ptr = pmd & ~(PTRS_PER_PTE * sizeof(void *) - 1); + ptr += PTRS_PER_PTE * sizeof(void *); + } + + return (ulong *)ptr; +} + +/* + * "Linux" PTE definitions. + */ +#define L_PTE_PRESENT (1 << 0) +#define L_PTE_YOUNG (1 << 1) +#define L_PTE_FILE (1 << 2) +#define L_PTE_DIRTY (1 << 6) +#define L_PTE_WRITE (1 << 7) +#define L_PTE_RDONLY L_PTE_WRITE +#define L_PTE_USER (1 << 8) +#define L_PTE_EXEC (1 << 9) +#define L_PTE_XN L_PTE_EXEC +#define L_PTE_SHARED (1 << 10) + +#define pte_val(pte) (pte) + +#define pte_present(pte) (pte_val(pte) & L_PTE_PRESENT) +#define pte_write(pte) (pte_val(pte) & L_PTE_WRITE) +#define pte_rdonly(pte) (pte_val(pte) & L_PTE_RDONLY) +#define pte_dirty(pte) (pte_val(pte) & L_PTE_DIRTY) +#define pte_young(pte) (pte_val(pte) & L_PTE_YOUNG) +#define pte_exec(pte) (pte_val(pte) & L_PTE_EXEC) +#define pte_xn(pte) (pte_val(pte) & L_PTE_XN) + +/* + * Following stuff is taken directly from the kernel sources. These are used in + * dump_exception_stack() to format an exception stack entry. + */ +#define USR26_MODE 0x00000000 +#define FIQ26_MODE 0x00000001 +#define IRQ26_MODE 0x00000002 +#define SVC26_MODE 0x00000003 +#define USR_MODE 0x00000010 +#define FIQ_MODE 0x00000011 +#define IRQ_MODE 0x00000012 +#define SVC_MODE 0x00000013 +#define ABT_MODE 0x00000017 +#define UND_MODE 0x0000001b +#define SYSTEM_MODE 0x0000001f +#define MODE32_BIT 0x00000010 +#define MODE_MASK 0x0000001f +#define PSR_T_BIT 0x00000020 +#define PSR_F_BIT 0x00000040 +#define PSR_I_BIT 0x00000080 +#define PSR_A_BIT 0x00000100 +#define PSR_E_BIT 0x00000200 +#define PSR_J_BIT 0x01000000 +#define PSR_Q_BIT 0x08000000 +#define PSR_V_BIT 0x10000000 +#define PSR_C_BIT 0x20000000 +#define PSR_Z_BIT 0x40000000 +#define PSR_N_BIT 0x80000000 + +#define isa_mode(regs) \ + ((((regs)->ARM_cpsr & PSR_J_BIT) >> 23) | \ + (((regs)->ARM_cpsr & PSR_T_BIT) >> 5)) + +#define processor_mode(regs) \ + ((regs)->ARM_cpsr & MODE_MASK) + +#define interrupts_enabled(regs) \ + (!((regs)->ARM_cpsr & PSR_I_BIT)) + +#define fast_interrupts_enabled(regs) \ + (!((regs)->ARM_cpsr & PSR_F_BIT)) + +static const char *processor_modes[] = { + "USER_26", "FIQ_26", "IRQ_26", "SVC_26", "UK4_26", "UK5_26", + "UK6_26", "UK7_26" , "UK8_26", "UK9_26", "UK10_26", "UK11_26", + "UK12_26", "UK13_26", "UK14_26", "UK15_26", "USER_32", "FIQ_32", + "IRQ_32", "SVC_32", "UK4_32", "UK5_32", "UK6_32", "ABT_32", + "UK8_32", "UK9_32", "UK10_32", "UND_32", "UK12_32", "UK13_32", + "UK14_32", "SYS_32", +}; + +static const char *isa_modes[] = { + "ARM" , "Thumb" , "Jazelle", "ThumbEE", +}; + +#define NOT_IMPLEMENTED() \ + error(FATAL, "%s: N/A\n", __func__) + +/* + * Do all necessary machine-specific setup here. This is called several times + * during initialization. + */ +void +arm_init(int when) +{ + ulong vaddr; + +#if defined(__i386__) || defined(__x86_64__) + if (ACTIVE()) + error(FATAL, "compiled for the ARM architecture\n"); +#endif + + switch (when) { + case PRE_SYMTAB: + machdep->verify_symbol = arm_verify_symbol; + machdep->machspec = &arm_machine_specific; + if (pc->flags & KERNEL_DEBUG_QUERY) + return; + machdep->pagesize = memory_page_size(); + machdep->pageshift = ffs(machdep->pagesize) - 1; + machdep->pageoffset = machdep->pagesize - 1; + machdep->pagemask = ~((ulonglong)machdep->pageoffset); + machdep->stacksize = machdep->pagesize * 2; + machdep->last_pgd_read = 0; + machdep->last_pmd_read = 0; + machdep->last_ptbl_read = 0; + machdep->verify_paddr = generic_verify_paddr; + machdep->ptrs_per_pgd = PTRS_PER_PGD; + + if (machdep->cmdline_args[0]) + arm_parse_cmdline_args(); + break; + + case PRE_GDB: + if ((machdep->pgd = (char *)malloc(PGDIR_SIZE())) == NULL) + error(FATAL, "cannot malloc pgd space."); + if ((machdep->ptbl = (char *)malloc(PAGESIZE())) == NULL) + error(FATAL, "cannot malloc ptbl space."); + + /* + * Kernel text starts 16k after PAGE_OFFSET. + */ + machdep->kvbase = symbol_value("_stext") & ~KVBASE_MASK; + machdep->identity_map_base = machdep->kvbase; + machdep->is_kvaddr = arm_is_kvaddr; + machdep->is_uvaddr = arm_is_uvaddr; + machdep->eframe_search = arm_eframe_search; + machdep->back_trace = arm_back_trace_cmd; + machdep->processor_speed = arm_processor_speed; + machdep->uvtop = arm_uvtop; + machdep->kvtop = arm_kvtop; + machdep->get_task_pgd = arm_get_task_pgd; + machdep->get_stack_frame = arm_get_stack_frame; + machdep->get_stackbase = generic_get_stackbase; + machdep->get_stacktop = generic_get_stacktop; + machdep->translate_pte = arm_translate_pte; + machdep->memory_size = generic_memory_size; + machdep->vmalloc_start = arm_vmalloc_start; + machdep->is_task_addr = arm_is_task_addr; + machdep->dis_filter = arm_dis_filter; + machdep->cmd_mach = arm_cmd_mach; + machdep->get_smp_cpus = arm_get_smp_cpus; + machdep->line_number_hooks = arm_line_number_hooks; + machdep->value_to_symbol = generic_machdep_value_to_symbol; + machdep->init_kernel_pgd = NULL; + machdep->dump_irq = generic_dump_irq; + machdep->show_interrupts = generic_show_interrupts; + machdep->get_irq_affinity = generic_get_irq_affinity; + + arm_init_machspec(); + break; + + case POST_GDB: + /* + * Starting from 2.6.38 hardware and Linux page tables + * were reordered. See also mainline kernel commit + * d30e45eeabe (ARM: pgtable: switch order of Linux vs + * hardware page tables). + */ + if (THIS_KERNEL_VERSION > LINUX(2,6,37) || + STRUCT_EXISTS("pteval_t")) + machdep->flags |= PGTABLE_V2; + + if (THIS_KERNEL_VERSION >= LINUX(3,3,0) || + symbol_exists("idmap_pgd")) + machdep->flags |= IDMAP_PGD; + + machdep->section_size_bits = _SECTION_SIZE_BITS; + machdep->max_physmem_bits = _MAX_PHYSMEM_BITS; + + if (symbol_exists("irq_desc")) + ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc, + "irq_desc", NULL, 0); + else if (kernel_symbol_exists("nr_irqs")) + get_symbol_data("nr_irqs", sizeof(unsigned int), + &machdep->nr_irqs); + /* + * Registers for idle threads are saved in + * thread_info.cpu_context. + */ + STRUCT_SIZE_INIT(cpu_context_save, "cpu_context_save"); + MEMBER_OFFSET_INIT(cpu_context_save_fp, + "cpu_context_save", "fp"); + MEMBER_OFFSET_INIT(cpu_context_save_sp, + "cpu_context_save", "sp"); + MEMBER_OFFSET_INIT(cpu_context_save_pc, + "cpu_context_save", "pc"); + MEMBER_OFFSET_INIT(thread_info_cpu_context, + "thread_info", "cpu_context"); + + /* + * We need to have information about note_buf_t which is used to + * hold ELF note containing registers and status of the thread + * that panic'd. + */ + STRUCT_SIZE_INIT(note_buf, "note_buf_t"); + + STRUCT_SIZE_INIT(elf_prstatus, "elf_prstatus"); + MEMBER_OFFSET_INIT(elf_prstatus_pr_pid, "elf_prstatus", + "pr_pid"); + MEMBER_OFFSET_INIT(elf_prstatus_pr_reg, "elf_prstatus", + "pr_reg"); + break; + + case POST_VM: + machdep->machspec->vmalloc_start_addr = vt->high_memory; + /* + * Modules are placed in first vmalloc'd area. This is 16MB + * below PAGE_OFFSET. + */ + machdep->machspec->modules_end = machdep->kvbase - 1; + vaddr = first_vmalloc_address(); + if (vaddr > machdep->machspec->modules_end) + machdep->machspec->modules_vaddr = DEFAULT_MODULES_VADDR; + else + machdep->machspec->modules_vaddr = vaddr; + + /* + * crash_notes contains machine specific information about the + * crash. In particular, it contains CPU registers at the time + * of the crash. We need this information to extract correct + * backtraces from the panic task. + */ + if (!ACTIVE() && !arm_get_crash_notes()) + error(WARNING, "could not retrieve crash_notes\n"); + + if (init_unwind_tables()) { + if (CRASHDEBUG(1)) + fprintf(fp, "using unwind tables\n"); + } else { + if (CRASHDEBUG(1)) + fprintf(fp, "using framepointers\n"); + } + break; + + case LOG_ONLY: + machdep->machspec = &arm_machine_specific; + machdep->kvbase = kt->vmcoreinfo._stext_SYMBOL & 0xffff0000UL; + arm_init_machspec(); + break; + } +} + +void +arm_dump_machdep_table(ulong arg) +{ + const struct machine_specific *ms; + int others, i; + + others = 0; + fprintf(fp, " flags: %lx (", machdep->flags); + if (machdep->flags & KSYMS_START) + fprintf(fp, "%sKSYMS_START", others++ ? "|" : ""); + if (machdep->flags & PHYS_BASE) + fprintf(fp, "%sPHYS_BASE", others++ ? "|" : ""); + if (machdep->flags & PGTABLE_V2) + fprintf(fp, "%sPGTABLE_V2", others++ ? "|" : ""); + if (machdep->flags & IDMAP_PGD) + fprintf(fp, "%sIDMAP_PGD", others++ ? "|" : ""); + fprintf(fp, ")\n"); + + fprintf(fp, " kvbase: %lx\n", machdep->kvbase); + fprintf(fp, " identity_map_base: %lx\n", machdep->kvbase); + fprintf(fp, " pagesize: %d\n", machdep->pagesize); + fprintf(fp, " pageshift: %d\n", machdep->pageshift); + fprintf(fp, " pagemask: %lx\n", (ulong)machdep->pagemask); + fprintf(fp, " pageoffset: %lx\n", machdep->pageoffset); + fprintf(fp, " stacksize: %ld\n", machdep->stacksize); + fprintf(fp, " hz: %d\n", machdep->hz); + fprintf(fp, " mhz: %ld\n", machdep->mhz); + fprintf(fp, " memsize: %lld (0x%llx)\n", + machdep->memsize, machdep->memsize); + fprintf(fp, " bits: %d\n", machdep->bits); + fprintf(fp, " nr_irqs: %d\n", machdep->nr_irqs); + fprintf(fp, " eframe_search: arm_eframe_search()\n"); + fprintf(fp, " back_trace: arm_back_trace_cmd()\n"); + fprintf(fp, " processor_speed: arm_processor_speed()\n"); + fprintf(fp, " uvtop: arm_uvtop()\n"); + fprintf(fp, " kvtop: arm_kvtop()\n"); + fprintf(fp, " get_task_pgd: arm_get_task_pgd()\n"); + fprintf(fp, " dump_irq: generic_dump_irq()\n"); + fprintf(fp, " get_stack_frame: arm_get_stack_frame()\n"); + fprintf(fp, " get_stackbase: generic_get_stackbase()\n"); + fprintf(fp, " get_stacktop: generic_get_stacktop()\n"); + fprintf(fp, " translate_pte: arm_translate_pte()\n"); + fprintf(fp, " memory_size: generic_memory_size()\n"); + fprintf(fp, " vmalloc_start: arm_vmalloc_start()\n"); + fprintf(fp, " is_task_addr: arm_is_task_addr()\n"); + fprintf(fp, " verify_symbol: arm_verify_symbol()\n"); + fprintf(fp, " dis_filter: arm_dis_filter()\n"); + fprintf(fp, " cmd_mach: arm_cmd_mach()\n"); + fprintf(fp, " get_smp_cpus: arm_get_smp_cpus()\n"); + fprintf(fp, " is_kvaddr: arm_is_kvaddr()\n"); + fprintf(fp, " is_uvaddr: arm_is_uvaddr()\n"); + fprintf(fp, " verify_paddr: generic_verify_paddr()\n"); + fprintf(fp, " show_interrupts: generic_show_interrupts()\n"); + fprintf(fp, " get_irq_affinity: generic_get_irq_affinity()\n"); + + fprintf(fp, " xendump_p2m_create: NULL\n"); + fprintf(fp, "xen_kdump_p2m_create: NULL\n"); + fprintf(fp, " line_number_hooks: arm_line_number_hooks\n"); + fprintf(fp, " last_pgd_read: %lx\n", machdep->last_pgd_read); + fprintf(fp, " last_pmd_read: %lx\n", machdep->last_pmd_read); + fprintf(fp, " last_ptbl_read: %lx\n", machdep->last_ptbl_read); + fprintf(fp, "clear_machdep_cache: NULL\n"); + fprintf(fp, " pgd: %lx\n", (ulong)machdep->pgd); + fprintf(fp, " pmd: %lx\n", (ulong)machdep->pmd); + fprintf(fp, " ptbl: %lx\n", (ulong)machdep->ptbl); + fprintf(fp, " ptrs_per_pgd: %d\n", machdep->ptrs_per_pgd); + fprintf(fp, " section_size_bits: %ld\n", machdep->section_size_bits); + fprintf(fp, " max_physmem_bits: %ld\n", machdep->max_physmem_bits); + fprintf(fp, " sections_per_root: %ld\n", machdep->sections_per_root); + + for (i = 0; i < MAX_MACHDEP_ARGS; i++) { + fprintf(fp, " cmdline_args[%d]: %s\n", + i, machdep->cmdline_args[i] ? + machdep->cmdline_args[i] : "(unused)"); + } + + ms = machdep->machspec; + + fprintf(fp, " machspec: %lx\n", (ulong)ms); + fprintf(fp, " phys_base: %lx\n", ms->phys_base); + fprintf(fp, " vmalloc_start_addr: %lx\n", ms->vmalloc_start_addr); + fprintf(fp, " modules_vaddr: %lx\n", ms->modules_vaddr); + fprintf(fp, " modules_end: %lx\n", ms->modules_end); + fprintf(fp, " kernel_text_start: %lx\n", ms->kernel_text_start); + fprintf(fp, " kernel_text_end: %lx\n", ms->kernel_text_end); + fprintf(fp, "exception_text_start: %lx\n", ms->exception_text_start); + fprintf(fp, " exception_text_end: %lx\n", ms->exception_text_end); + fprintf(fp, " crash_task_regs: %lx\n", (ulong)ms->crash_task_regs); + fprintf(fp, "unwind_index_prel31: %d\n", ms->unwind_index_prel31); +} + +/* + * Parse machine dependent command line arguments. + * + * Force the phys_base address via: + * + * --machdep phys_base=
+ */ +static void +arm_parse_cmdline_args(void) +{ + int index, i, c, err; + char *arglist[MAXARGS]; + char buf[BUFSIZE]; + char *p; + ulong value = 0; + + for (index = 0; index < MAX_MACHDEP_ARGS; index++) { + if (!machdep->cmdline_args[index]) + break; + + if (!strstr(machdep->cmdline_args[index], "=")) { + error(WARNING, "ignoring --machdep option: %x\n", + machdep->cmdline_args[index]); + continue; + } + + strcpy(buf, machdep->cmdline_args[index]); + + for (p = buf; *p; p++) { + if (*p == ',') + *p = ' '; + } + + c = parse_line(buf, arglist); + + for (i = 0; i < c; i++) { + err = 0; + + if (STRNEQ(arglist[i], "phys_base=")) { + int megabytes = FALSE; + int flags = RETURN_ON_ERROR | QUIET; + + if ((LASTCHAR(arglist[i]) == 'm') || + (LASTCHAR(arglist[i]) == 'M')) { + LASTCHAR(arglist[i]) = NULLCHAR; + megabytes = TRUE; + } + + p = arglist[i] + strlen("phys_base="); + if (strlen(p)) { + if (megabytes) + value = dtol(p, flags, &err); + else + value = htol(p, flags, &err); + } + + if (!err) { + if (megabytes) + value = MEGABYTES(value); + + machdep->machspec->phys_base = value; + + error(NOTE, + "setting phys_base to: 0x%lx\n", + machdep->machspec->phys_base); + + machdep->flags |= PHYS_BASE; + continue; + } + } + + error(WARNING, "ignoring --machdep option: %s\n", + arglist[i]); + } + } +} + +/* + * Retrieve task registers for the time of the crash. + */ +static int +arm_get_crash_notes(void) +{ + struct machine_specific *ms = machdep->machspec; + ulong crash_notes; + Elf32_Nhdr *note; + ulong offset; + char *buf, *p; + ulong *notes_ptrs; + ulong i; + + if (!symbol_exists("crash_notes")) + return FALSE; + + crash_notes = symbol_value("crash_notes"); + + notes_ptrs = (ulong *)GETBUF(kt->cpus*sizeof(notes_ptrs[0])); + + /* + * Read crash_notes for the first CPU. crash_notes are in standard ELF + * note format. + */ + if (!readmem(crash_notes, KVADDR, ¬es_ptrs[kt->cpus-1], + sizeof(notes_ptrs[kt->cpus-1]), "crash_notes", + RETURN_ON_ERROR)) { + error(WARNING, "cannot read crash_notes\n"); + FREEBUF(notes_ptrs); + return FALSE; + } + + if (symbol_exists("__per_cpu_offset")) { + + /* Add __per_cpu_offset for each cpu to form the pointer to the notes */ + for (i = 0; icpus; i++) + notes_ptrs[i] = notes_ptrs[kt->cpus-1] + kt->__per_cpu_offset[i]; + } + + buf = GETBUF(SIZE(note_buf)); + + if (!(panic_task_regs = malloc(kt->cpus*sizeof(*panic_task_regs)))) + error(FATAL, "cannot malloc panic_task_regs space\n"); + + for (i=0;icpus;i++) { + + if (!readmem(notes_ptrs[i], KVADDR, buf, SIZE(note_buf), "note_buf_t", + RETURN_ON_ERROR)) { + error(WARNING, "failed to read note_buf_t\n"); + goto fail; + } + + /* + * Do some sanity checks for this note before reading registers from it. + */ + note = (Elf32_Nhdr *)buf; + p = buf + sizeof(Elf32_Nhdr); + + if (note->n_type != NT_PRSTATUS) { + error(WARNING, "invalid note (n_type != NT_PRSTATUS)\n"); + goto fail; + } + if (p[0] != 'C' || p[1] != 'O' || p[2] != 'R' || p[3] != 'E') { + error(WARNING, "invalid note (name != \"CORE\"\n"); + goto fail; + } + + /* + * Find correct location of note data. This contains elf_prstatus + * structure which has registers etc. for the crashed task. + */ + offset = sizeof(Elf32_Nhdr); + offset = roundup(offset + note->n_namesz, 4); + p = buf + offset; /* start of elf_prstatus */ + + BCOPY(p + OFFSET(elf_prstatus_pr_reg), &panic_task_regs[i], + sizeof(panic_task_regs[i])); + + } + + /* + * And finally we have the registers for the crashed task. This is + * used later on when dumping backtrace. + */ + ms->crash_task_regs = panic_task_regs; + + FREEBUF(buf); + FREEBUF(notes_ptrs); + return TRUE; + +fail: + FREEBUF(buf); + FREEBUF(notes_ptrs); + free(panic_task_regs); + return FALSE; +} + +/* + * Accept or reject a symbol from the kernel namelist. + */ +static int +arm_verify_symbol(const char *name, ulong value, char type) +{ + if (STREQ(name, "swapper_pg_dir")) + machdep->flags |= KSYMS_START; + + if (!name || !strlen(name) || !(machdep->flags & KSYMS_START)) + return FALSE; + + if (STREQ(name, "$a") || STREQ(name, "$n") || STREQ(name, "$d")) + return FALSE; + + if (STREQ(name, "PRRR") || STREQ(name, "NMRR")) + return FALSE; + + if ((type == 'A') && STRNEQ(name, "__crc_")) + return FALSE; + + if (CRASHDEBUG(8) && name && strlen(name)) + fprintf(fp, "%08lx %s\n", value, name); + + return TRUE; +} + +static int +arm_is_module_addr(ulong vaddr) +{ + ulong modules_start; + ulong modules_end = machdep->machspec->modules_end; + + if (!MODULES_VADDR) { + /* + * In case we are still initializing, and vm_init() has not been + * called, we use defaults here which is 16MB below kernel start + * address. + */ + modules_start = DEFAULT_MODULES_VADDR; + } else { + modules_start = MODULES_VADDR; + } + + return (vaddr >= modules_start && vaddr <= modules_end); +} + +int +arm_is_vmalloc_addr(ulong vaddr) +{ + if (arm_is_module_addr(vaddr)) + return TRUE; + + if (!VMALLOC_START) + return FALSE; + + return (vaddr >= VMALLOC_START); +} + +/* + * Check whether given address falls inside kernel address space (including + * modules). + */ +static int +arm_is_kvaddr(ulong vaddr) +{ + if (arm_is_module_addr(vaddr)) + return TRUE; + + return (vaddr >= machdep->kvbase); +} + +static int +arm_is_uvaddr(ulong vaddr, struct task_context *unused) +{ + if (arm_is_module_addr(vaddr)) + return FALSE; + + return (vaddr < machdep->kvbase); +} + +/* + * Returns TRUE if given pc is in exception area. + */ +static int +arm_in_exception_text(ulong pc) +{ + ulong exception_start = machdep->machspec->exception_text_start; + ulong exception_end = machdep->machspec->exception_text_end; + + if (exception_start && exception_end) + return (pc >= exception_start && pc < exception_end); + + return FALSE; +} + +/* + * Returns TRUE if given pc points to a return from syscall + * entrypoint. In case the function returns TRUE and if offset is given, + * it is filled with the offset that should be added to the SP to get + * address of the exception frame where the user registers are. + */ +static int +arm_in_ret_from_syscall(ulong pc, int *offset) +{ + /* + * On fast syscall return path, the stack looks like: + * + * SP + 0 {r4, r5} + * SP + 8 user pt_regs + * + * The asm syscall handler pushes fifth and sixth registers + * onto the stack before calling the actual syscall handler. + * + * So in order to print out the user registers at the time + * the syscall was made, we need to adjust SP for 8. + */ + if (pc == symbol_value("ret_fast_syscall")) { + if (offset) + *offset = 8; + return TRUE; + } + + /* + * In case we are on the slow syscall path, the SP already + * points to the start of the user registers hence no + * adjustments needs to be done. + */ + if (pc == symbol_value("ret_slow_syscall")) { + if (offset) + *offset = 0; + return TRUE; + } + + return FALSE; +} + +/* + * Unroll the kernel stack using a minimal amount of gdb services. + */ +static void +arm_back_trace(struct bt_info *bt) +{ + int n = 0; + + /* + * In case bt->machdep contains pointer to a full register set, we take + * FP from there. + */ + if (bt->machdep) { + const struct arm_pt_regs *regs = bt->machdep; + bt->frameptr = regs->ARM_fp; + } + + /* + * Stack frame layout: + * optionally saved caller registers (r4 - r10) + * saved fp + * saved sp + * saved lr + * frame => saved pc + * optionally saved arguments (r0 - r3) + * saved sp => + * + * Functions start with the following code sequence: + * mov ip, sp + * stmfd sp!, {r0 - r3} (optional) + * corrected pc => stmfd sp!, {..., fp, ip, lr, pc} + */ + while (bt->frameptr && INSTACK(bt->frameptr, bt)) { + ulong from; + ulong sp; + + /* + * We correct the PC to point to the actual instruction (current + * value is PC + 8). + */ + bt->instptr = GET_STACK_ULONG(bt->frameptr - 0); + bt->instptr -= 8; + + /* + * Now get LR, saved SP and FP from the frame as well. + */ + from = GET_STACK_ULONG(bt->frameptr - 4); + sp = GET_STACK_ULONG(bt->frameptr - 8); + bt->frameptr = GET_STACK_ULONG(bt->frameptr - 12); + + arm_dump_backtrace_entry(bt, n++, from, sp); + + bt->stkptr = sp; + } +} + +/* + * Unroll a kernel stack. + */ +static void +arm_back_trace_cmd(struct bt_info *bt) +{ + if (kt->flags & DWARF_UNWIND) + unwind_backtrace(bt); + else + arm_back_trace(bt); +} + +/* + * Calculate and return the speed of the processor. + */ +static ulong +arm_processor_speed(void) +{ + /* + * For now, we don't support reading CPU speed. + */ + return 0; +} + +/* + * Translate a PTE, returning TRUE if the page is present. If a physaddr pointer + * is passed in, don't print anything. + */ +static int +arm_translate_pte(ulong pte, void *physaddr, ulonglong pae_pte) +{ + char ptebuf[BUFSIZE]; + char physbuf[BUFSIZE]; + char buf[BUFSIZE]; + int page_present; + ulong paddr; + int len1, len2, others; + + page_present = pte_present(pte); + paddr = PAGEBASE(pte); + + if (physaddr) { + *((ulong *)physaddr) = paddr; + return page_present; + } + + sprintf(ptebuf, "%lx", pte); + len1 = MAX(strlen(ptebuf), strlen("PTE")); + fprintf(fp, "%s ", mkstring(buf, len1, CENTER | LJUST, "PTE")); + + if (!page_present && pte) { + /* swap page, not handled yet */ + return page_present; + } + + sprintf(physbuf, "%lx", paddr); + len2 = MAX(strlen(physbuf), strlen("PHYSICAL")); + fprintf(fp, "%s ", mkstring(buf, len2, CENTER | LJUST, "PHYSICAL")); + + fprintf(fp, "FLAGS\n"); + fprintf(fp, "%s %s ", + mkstring(ptebuf, len1, CENTER | RJUST, NULL), + mkstring(physbuf, len2, CENTER | RJUST, NULL)); + + fprintf(fp, "("); + others = 0; + + if (pte) { + if (pte_present(pte)) + fprintf(fp, "%sPRESENT", others++ ? "|" : ""); + if (pte_dirty(pte)) + fprintf(fp, "%sDIRTY", others++ ? "|" : ""); + if (pte_young(pte)) + fprintf(fp, "%sYOUNG", others++ ? "|" : ""); + if (machdep->flags & PGTABLE_V2) { + if (!pte_rdonly(pte)) + fprintf(fp, "%sWRITE", others++ ? "|" : ""); + if (!pte_xn(pte)) + fprintf(fp, "%sEXEC", others++ ? "|" : ""); + } else { + if (pte_write(pte)) + fprintf(fp, "%sWRITE", others++ ? "|" : ""); + if (pte_exec(pte)) + fprintf(fp, "%sEXEC", others++ ? "|" : ""); + } + } else { + fprintf(fp, "no mapping"); + } + + fprintf(fp, ")\n"); + + return 0; +} + +/* + * Virtual to physical memory translation. This function will be called by both + * arm_kvtop() and arm_uvtop(). + */ +static int +arm_vtop(ulong vaddr, ulong *pgd, physaddr_t *paddr, int verbose) +{ + char buf[BUFSIZE]; + ulong *page_dir; + ulong *page_middle; + ulong *page_table; + ulong pgd_pte; + ulong pmd_pte; + ulong pte; + + /* + * Page tables in ARM Linux + * + * In hardware PGD is 16k (having 4096 pointers to PTE) and PTE is 1k + * (containing 256 translations). + * + * Linux, however, wants to have PTEs as page sized entities. This means + * that in ARM Linux we have following setup (see also + * arch/arm/include/asm/pgtable.h) + * + * Before 2.6.38 + * + * PGD PTE + * +---------+ + * | | 0 ----> +------------+ + * +- - - - -+ | h/w pt 0 | + * | | 4 ----> +------------+ +1024 + * +- - - - -+ | h/w pt 1 | + * . . +------------+ +2048 + * . . | Linux pt 0 | + * . . +------------+ +3072 + * | | 4095 | Linux pt 1 | + * +---------+ +------------+ +4096 + * + * Starting from 2.6.38 + * + * PGD PTE + * +---------+ + * | | 0 ----> +------------+ + * +- - - - -+ | Linux pt 0 | + * | | 4 ----> +------------+ +1024 + * +- - - - -+ | Linux pt 1 | + * . . +------------+ +2048 + * . . | h/w pt 0 | + * . . +------------+ +3072 + * | | 4095 | h/w pt 1 | + * +---------+ +------------+ +4096 + * + * So in Linux implementation we have two hardware pointers to second + * level page tables. Depending on the kernel version, the "Linux" page + * tables either follow or precede the hardware tables. + * + * Linux PT entries contain bits that are not supported on hardware, for + * example "young" and "dirty" flags. + * + * Our translation scheme only uses Linux PTEs here. + */ + + if (verbose) + fprintf(fp, "PAGE DIRECTORY: %lx\n", (ulong)pgd); + + /* + * pgd_offset(pgd, vaddr) + */ + page_dir = pgd + PGD_OFFSET(vaddr) * 2; + + /* The unity-mapped region is mapped using 1MB pages, + * hence 1-level translation if bit 20 is set; if we + * are 1MB apart physically, we move the page_dir in + * case bit 20 is set. + */ + if (((vaddr) >> (20)) & 1) + page_dir = page_dir + 1; + + FILL_PGD(PAGEBASE(pgd), KVADDR, PGDIR_SIZE()); + pgd_pte = ULONG(machdep->pgd + PGDIR_OFFSET(page_dir)); + + if (verbose) + fprintf(fp, " PGD: %s => %lx\n", + mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, + MKSTR((ulong)page_dir)), pgd_pte); + + if (!pgd_pte) + return FALSE; + + /* + * pmd_offset(pgd, vaddr) + * + * Here PMD is folded into a PGD. + */ + pmd_pte = pgd_pte; + page_middle = page_dir; + + if (verbose) + fprintf(fp, " PMD: %s => %lx\n", + mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, + MKSTR((ulong)page_middle)), pmd_pte); + + if ((pmd_pte & PMD_TYPE_MASK) == PMD_TYPE_SECT) { + ulong sectionbase = pmd_pte & _SECTION_PAGE_MASK; + + if (verbose) { + fprintf(fp, " PAGE: %s (1MB)\n\n", + mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, + MKSTR(sectionbase))); + } + *paddr = sectionbase + (vaddr & ~_SECTION_PAGE_MASK); + return TRUE; + } + + /* + * pte_offset_map(pmd, vaddr) + */ + page_table = pmd_page_addr(pmd_pte) + PTE_OFFSET(vaddr); + + FILL_PTBL(PAGEBASE(page_table), PHYSADDR, PAGESIZE()); + pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table)); + + if (verbose) { + fprintf(fp, " PTE: %s => %lx\n\n", + mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, + MKSTR((ulong)page_table)), pte); + } + + if (!pte_present(pte)) { + if (pte && verbose) { + fprintf(fp, "\n"); + arm_translate_pte(pte, 0, 0); + } + return FALSE; + } + + *paddr = PAGEBASE(pte) + PAGEOFFSET(vaddr); + + if (verbose) { + fprintf(fp, " PAGE: %s\n\n", + mkstring(buf, VADDR_PRLEN, RJUST | LONG_HEX, + MKSTR(PAGEBASE(pte)))); + arm_translate_pte(pte, 0, 0); + } + + return TRUE; +} + +/* + * Translates a user virtual address to its physical address. cmd_vtop() sets + * the verbose flag so that the pte translation gets displayed; all other + * callers quietly accept the translation. + */ +static int +arm_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbose) +{ + ulong *pgd; + + if (!tc) + error(FATAL, "current context invalid\n"); + + /* + * Before idmap_pgd was introduced with upstream commit 2c8951ab0c + * (ARM: idmap: use idmap_pgd when setting up mm for reboot), the + * panic task pgd was overwritten by soft reboot code, so we can't do + * any vtop translations. + */ + if (!(machdep->flags & IDMAP_PGD) && tc->task == tt->panic_task) + error(FATAL, "panic task pgd is trashed by soft reboot code\n"); + + *paddr = 0; + + if (is_kernel_thread(tc->task) && IS_KVADDR(uvaddr)) { + ulong active_mm; + + readmem(tc->task + OFFSET(task_struct_active_mm), + KVADDR, &active_mm, sizeof(void *), + "task active_mm contents", FAULT_ON_ERROR); + + if (!active_mm) + error(FATAL, + "no active_mm for this kernel thread\n"); + + readmem(active_mm + OFFSET(mm_struct_pgd), + KVADDR, &pgd, sizeof(long), + "mm_struct pgd", FAULT_ON_ERROR); + } else { + ulong mm; + + mm = task_mm(tc->task, TRUE); + if (mm) + pgd = ULONG_PTR(tt->mm_struct + OFFSET(mm_struct_pgd)); + else + readmem(tc->mm_struct + OFFSET(mm_struct_pgd), + KVADDR, &pgd, sizeof(long), "mm_struct pgd", + FAULT_ON_ERROR); + } + + return arm_vtop(uvaddr, pgd, paddr, verbose); +} + +/* + * Translates a kernel virtual address to its physical address. cmd_vtop() sets + * the verbose flag so that the pte translation gets displayed; all other + * callers quietly accept the translation. + */ +static int +arm_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose) +{ + if (!IS_KVADDR(kvaddr)) + return FALSE; + + if (!vt->vmalloc_start) { + *paddr = VTOP(kvaddr); + return TRUE; + } + + if (!IS_VMALLOC_ADDR(kvaddr)) { + *paddr = VTOP(kvaddr); + if (!verbose) + return TRUE; + } + + return arm_vtop(kvaddr, (ulong *)vt->kernel_pgd[0], paddr, verbose); +} + +/* + * Get SP and PC values for idle tasks. + */ +static int +arm_get_frame(struct bt_info *bt, ulong *pcp, ulong *spp) +{ + const char *cpu_context; + + if (!bt->tc || !(tt->flags & THREAD_INFO)) + return FALSE; + + /* + * Update thread_info in tt. + */ + if (!fill_thread_info(bt->tc->thread_info)) + return FALSE; + + cpu_context = tt->thread_info + OFFSET(thread_info_cpu_context); + +#define GET_REG(ptr, cp, off) ((*ptr) = (*((ulong *)((cp) + OFFSET(off))))) + /* + * Unwinding code needs FP value also so we pass it with bt. + */ + GET_REG(&bt->frameptr, cpu_context, cpu_context_save_fp); + GET_REG(spp, cpu_context, cpu_context_save_sp); + GET_REG(pcp, cpu_context, cpu_context_save_pc); + + return TRUE; +} + +/* + * Get the starting point for the active cpu in a diskdump. + */ +static int +arm_get_dumpfile_stack_frame(struct bt_info *bt, ulong *nip, ulong *ksp) +{ + const struct machine_specific *ms = machdep->machspec; + + if (!ms->crash_task_regs) + return FALSE; + + if (!is_task_active(bt->task)) + return FALSE; + + /* + * We got registers for panic task from crash_notes. Just return them. + */ + *nip = ms->crash_task_regs[bt->tc->processor].ARM_pc; + *ksp = ms->crash_task_regs[bt->tc->processor].ARM_sp; + + /* + * Also store pointer to all registers in case unwinding code needs + * to access LR. + */ + bt->machdep = &(ms->crash_task_regs[bt->tc->processor]); + + return TRUE; +} + +/* + * Get a stack frame combination of PC and SP from the most relevant spot. + */ +static void +arm_get_stack_frame(struct bt_info *bt, ulong *pcp, ulong *spp) +{ + ulong ip, sp; + int ret; + + ip = sp = 0; + bt->machdep = NULL; + + if (DUMPFILE() && is_task_active(bt->task)) + ret = arm_get_dumpfile_stack_frame(bt, &ip, &sp); + else + ret = arm_get_frame(bt, &ip, &sp); + + if (!ret) { + error(WARNING, "cannot get stackframe for task\n"); + return; + } + + if (pcp) + *pcp = ip; + if (spp) + *spp = sp; +} + +/* + * Prints out exception stack starting from start. + */ +void +arm_dump_exception_stack(ulong start, ulong end) +{ + struct arm_pt_regs regs; + ulong flags; + char buf[64]; + + if (!readmem(start, KVADDR, ®s, sizeof(regs), + "exception regs", RETURN_ON_ERROR)) { + error(WARNING, "failed to read exception registers\n"); + return; + } + + fprintf(fp, " pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n" + " sp : %08lx ip : %08lx fp : %08lx\n", + regs.ARM_pc, regs.ARM_lr, regs.ARM_cpsr, + regs.ARM_sp, regs.ARM_ip, regs.ARM_fp); + fprintf(fp, " r10: %08lx r9 : %08lx r8 : %08lx\n", + regs.ARM_r10, regs.ARM_r9, regs.ARM_r8); + fprintf(fp, " r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n", + regs.ARM_r7, regs.ARM_r6, + regs.ARM_r5, regs.ARM_r4); + fprintf(fp, " r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n", + regs.ARM_r3, regs.ARM_r2, + regs.ARM_r1, regs.ARM_r0); + + flags = regs.ARM_cpsr; + buf[0] = flags & PSR_N_BIT ? 'N' : 'n'; + buf[1] = flags & PSR_Z_BIT ? 'Z' : 'z'; + buf[2] = flags & PSR_C_BIT ? 'C' : 'c'; + buf[3] = flags & PSR_V_BIT ? 'V' : 'v'; + buf[4] = '\0'; + + fprintf(fp, " Flags: %s IRQs o%s FIQs o%s Mode %s ISA %s\n", + buf, interrupts_enabled(®s) ? "n" : "ff", + fast_interrupts_enabled(®s) ? "n" : "ff", + processor_modes[processor_mode(®s)], + isa_modes[isa_mode(®s)]); +} + +static void +arm_display_full_frame(struct bt_info *bt, ulong sp) +{ + ulong words, addr; + ulong *up; + char buf[BUFSIZE]; + int i, u_idx; + + if (!INSTACK(sp, bt) || !INSTACK(bt->stkptr, bt)) + return; + + words = (sp - bt->stkptr) / sizeof(ulong); + + if (words == 0) { + fprintf(fp, " (no frame)\n"); + return; + } + + addr = bt->stkptr; + u_idx = (bt->stkptr - bt->stackbase) / sizeof(ulong); + for (i = 0; i < words; i++, u_idx++) { + if ((i % 4) == 0) + fprintf(fp, "%s %lx: ", i ? "\n" : "", addr); + + up = (ulong *)(&bt->stackbuf[u_idx * sizeof(ulong)]); + fprintf(fp, "%s ", format_stack_entry(bt, buf, *up, 0)); + addr += sizeof(ulong); + } + fprintf(fp, "\n"); +} + +/* + * Prints out a single stack frame. What is printed depends on flags passed in + * with bt. + * + * What is expected when calling this function: + * bt->frameptr = current FP (or 0 if there is no such) + * bt->stkptr = current SP + * bt->instptr = current PC + * + * from = LR + * sp = previous/saved SP + */ +void +arm_dump_backtrace_entry(struct bt_info *bt, int level, ulong from, ulong sp) +{ + struct load_module *lm; + const char *name; + int offset = 0; + struct syment *symp; + ulong symbol_offset; + char *name_plus_offset; + char buf[BUFSIZE]; + + name = closest_symbol(bt->instptr); + + name_plus_offset = NULL; + if (bt->flags & BT_SYMBOL_OFFSET) { + symp = value_search(bt->instptr, &symbol_offset); + + if (symp && symbol_offset) + name_plus_offset = + value_to_symstr(bt->instptr, buf, bt->radix); + } + + if (module_symbol(bt->instptr, NULL, &lm, NULL, 0)) { + fprintf(fp, "%s#%d [<%08lx>] (%s [%s]) from [<%08lx>]\n", + level < 10 ? " " : "", + level, bt->instptr, + name_plus_offset ? name_plus_offset : name, + lm->mod_name, from); + } else { + fprintf(fp, "%s#%d [<%08lx>] (%s) from [<%08lx>]\n", + level < 10 ? " " : "", + level, bt->instptr, + name_plus_offset ? name_plus_offset : name, from); + } + + if (bt->flags & BT_LINE_NUMBERS) { + char buf[BUFSIZE]; + + get_line_number(bt->instptr, buf, FALSE); + if (strlen(buf)) + fprintf(fp, " %s\n", buf); + } + + if (arm_in_exception_text(bt->instptr)) { + arm_dump_exception_stack(sp, sp + sizeof(struct arm_pt_regs)); + } else if (arm_in_ret_from_syscall(from, &offset)) { + ulong nsp = sp + offset; + + arm_dump_exception_stack(nsp, nsp + sizeof(struct arm_pt_regs)); + } + + if (bt->flags & BT_FULL) { + if (kt->flags & DWARF_UNWIND) { + fprintf(fp, " " + "[PC: %08lx LR: %08lx SP: %08lx SIZE: %ld]\n", + bt->instptr, from, bt->stkptr, sp - bt->stkptr); + } else { + fprintf(fp, " " + "[PC: %08lx LR: %08lx SP: %08lx FP: %08lx " + "SIZE: %ld]\n", + bt->instptr, from, bt->stkptr, bt->frameptr, + sp - bt->stkptr); + } + arm_display_full_frame(bt, sp); + } +} + +/* + * Determine where vmalloc'd memory starts. + */ +static ulong +arm_vmalloc_start(void) +{ + return vt->high_memory; +} + +/* + * Checks whether given task is valid task address. + */ +static int +arm_is_task_addr(ulong task) +{ + if (tt->flags & THREAD_INFO) + return IS_KVADDR(task); + + return (IS_KVADDR(task) && ALIGNED_STACK_OFFSET(task) == 0); +} + +/* + * Filter dissassembly output if the output radix is not gdb's default 10 + */ +static int +arm_dis_filter(ulong vaddr, char *inbuf, unsigned int output_radix) +{ + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char *colon, *p1; + int argc; + char *argv[MAXARGS]; + ulong value; + + if (!inbuf) + return TRUE; +/* + * For some reason gdb can go off into the weeds translating text addresses, + * (on alpha -- not necessarily seen on arm) so this routine both fixes the + * references as well as imposing the current output radix on the translations. + */ + console("IN: %s", inbuf); + + colon = strstr(inbuf, ":"); + + if (colon) { + sprintf(buf1, "0x%lx <%s>", vaddr, + value_to_symstr(vaddr, buf2, output_radix)); + sprintf(buf2, "%s%s", buf1, colon); + strcpy(inbuf, buf2); + } + + strcpy(buf1, inbuf); + argc = parse_line(buf1, argv); + + if ((FIRSTCHAR(argv[argc-1]) == '<') && + (LASTCHAR(argv[argc-1]) == '>')) { + p1 = rindex(inbuf, '<'); + while ((p1 > inbuf) && !STRNEQ(p1, " 0x")) + p1--; + + if (!STRNEQ(p1, " 0x")) + return FALSE; + p1++; + + if (!extract_hex(p1, &value, NULLCHAR, TRUE)) + return FALSE; + + sprintf(buf1, "0x%lx <%s>\n", value, + value_to_symstr(value, buf2, output_radix)); + + sprintf(p1, "%s", buf1); + } + + console(" %s", inbuf); + + return TRUE; +} + +/* + * Look for likely exception frames in a stack. + */ +static int +arm_eframe_search(struct bt_info *bt) +{ + return (NOT_IMPLEMENTED()); +} + +/* + * Get the relevant page directory pointer from a task structure. + */ +static ulong +arm_get_task_pgd(ulong task) +{ + return (NOT_IMPLEMENTED()); +} + +/* + * Machine dependent command. + */ +static void +arm_cmd_mach(void) +{ + int c; + + while ((c = getopt(argcnt, args, "cm")) != -1) { + switch (c) { + case 'c': + case 'm': + fprintf(fp, "ARM: '-%c' option is not supported\n", c); + break; + + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + arm_display_machine_stats(); +} + +static void +arm_display_machine_stats(void) +{ + struct new_utsname *uts; + char buf[BUFSIZE]; + ulong mhz; + + uts = &kt->utsname; + + fprintf(fp, " MACHINE TYPE: %s\n", uts->machine); + fprintf(fp, " MEMORY SIZE: %s\n", get_memory_size(buf)); + fprintf(fp, " CPUS: %d\n", get_cpus_to_display()); + fprintf(fp, " PROCESSOR SPEED: "); + if ((mhz = machdep->processor_speed())) + fprintf(fp, "%ld Mhz\n", mhz); + else + fprintf(fp, "(unknown)\n"); + fprintf(fp, " HZ: %d\n", machdep->hz); + fprintf(fp, " PAGE SIZE: %d\n", PAGESIZE()); + fprintf(fp, "KERNEL VIRTUAL BASE: %lx\n", machdep->kvbase); + fprintf(fp, "KERNEL MODULES BASE: %lx\n", MODULES_VADDR); + fprintf(fp, "KERNEL VMALLOC BASE: %lx\n", vt->vmalloc_start); + fprintf(fp, " KERNEL STACK SIZE: %ld\n", STACKSIZE()); +} + +static int +arm_get_smp_cpus(void) +{ + return get_cpus_online(); +} + +/* + * Initialize ARM specific stuff. + */ +static void +arm_init_machspec(void) +{ + struct machine_specific *ms = machdep->machspec; + ulong phys_base; + + if (symbol_exists("__exception_text_start") && + symbol_exists("__exception_text_end")) { + ms->exception_text_start = symbol_value("__exception_text_start"); + ms->exception_text_end = symbol_value("__exception_text_end"); + } + + if (symbol_exists("_stext") && symbol_exists("_etext")) { + ms->kernel_text_start = symbol_value("_stext"); + ms->kernel_text_end = symbol_value("_etext"); + } + + if (CRASHDEBUG(1)) { + fprintf(fp, "kernel text: [%lx - %lx]\n", + ms->kernel_text_start, ms->kernel_text_end); + fprintf(fp, "exception text: [%lx - %lx]\n", + ms->exception_text_start, ms->exception_text_end); + } + + if (machdep->flags & PHYS_BASE) /* --machdep override */ + return; + + /* + * Next determine suitable value for phys_base. User can override this + * by passing valid '--machdep phys_base=' option. + */ + ms->phys_base = 0; + + if (ACTIVE()) { + char buf[BUFSIZE]; + char *p1; + int errflag; + FILE *fp; + + if ((fp = fopen("/proc/iomem", "r")) == NULL) + return; + + /* + * Memory regions are sorted in ascending order. We take the + * first region which should be correct for most uses. + */ + errflag = 1; + while (fgets(buf, BUFSIZE, fp)) { + if (strstr(buf, ": System RAM")) { + clean_line(buf); + errflag = 0; + break; + } + } + fclose(fp); + + if (errflag) + return; + + if (!(p1 = strstr(buf, "-"))) + return; + + *p1 = NULLCHAR; + + phys_base = htol(buf, RETURN_ON_ERROR | QUIET, &errflag); + if (errflag) + return; + + ms->phys_base = phys_base; + } else if (DISKDUMP_DUMPFILE() && diskdump_phys_base(&phys_base)) { + ms->phys_base = phys_base; + } else if (KDUMP_DUMPFILE() && arm_kdump_phys_base(&phys_base)) { + ms->phys_base = phys_base; + } else { + error(WARNING, + "phys_base cannot be determined from the dumpfile.\n" + "Using default value of 0. If this is not correct,\n" + "consider using '--machdep phys_base='\n"); + } + + if (CRASHDEBUG(1)) + fprintf(fp, "using %lx as phys_base\n", ms->phys_base); +} + +static const char *hook_files[] = { + "arch/arm/kernel/entry-armv.S", + "arch/arm/kernel/entry-common.S", +}; + +#define ENTRY_ARMV_S ((char **)&hook_files[0]) +#define ENTRY_COMMON_S ((char **)&hook_files[1]) + +static struct line_number_hook arm_line_number_hooks[] = { + { "__dabt_svc", ENTRY_ARMV_S }, + { "__irq_svc", ENTRY_ARMV_S }, + { "__und_svc", ENTRY_ARMV_S }, + { "__pabt_svc", ENTRY_ARMV_S }, + { "__switch_to", ENTRY_ARMV_S }, + + { "ret_fast_syscall", ENTRY_COMMON_S }, + { "ret_slow_syscall", ENTRY_COMMON_S }, + { "ret_from_fork", ENTRY_COMMON_S }, + { NULL, NULL }, +}; +#endif /* ARM */ diff --git a/arm64.c b/arm64.c new file mode 100644 index 00000000..f05648bd --- /dev/null +++ b/arm64.c @@ -0,0 +1,1351 @@ +/* + * arm64.c - core analysis suite + * + * Copyright (C) 2012,2013 David Anderson + * Copyright (C) 2012,2013 Red Hat, Inc. 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. + */ + +#ifdef ARM64 + +#include "defs.h" +#include + +#define NOT_IMPLEMENTED(X) error((X), "%s: function not implemented\n", __func__) + +static struct machine_specific arm64_machine_specific = { 0 }; +static int arm64_verify_symbol(const char *, ulong, char); +static void arm64_parse_cmdline_args(void); +static void arm64_calc_phys_offset(void); +static int arm64_kdump_phys_base(ulong *); +static ulong arm64_processor_speed(void); +static void arm64_init_kernel_pgd(void); +static int arm64_kvtop(struct task_context *, ulong, physaddr_t *, int); +static int arm64_uvtop(struct task_context *, ulong, physaddr_t *, int); +static int arm64_vtop_2level_64k(ulong, ulong, physaddr_t *, int); +static int arm64_vtop_3level_4k(ulong, ulong, physaddr_t *, int); +static ulong arm64_get_task_pgd(ulong); +static void arm64_stackframe_init(void); +static int arm64_eframe_search(struct bt_info *); +static int arm64_in_exception_text(ulong); +static void arm64_back_trace_cmd(struct bt_info *); +static void arm64_print_stackframe_entry(struct bt_info *, int, struct arm64_stackframe *); +static int arm64_unwind_frame(struct bt_info *, struct arm64_stackframe *); +static int arm64_get_dumpfile_stackframe(struct bt_info *, struct arm64_stackframe *); +static int arm64_get_stackframe(struct bt_info *, struct arm64_stackframe *); +static void arm64_get_stack_frame(struct bt_info *, ulong *, ulong *); +static int arm64_translate_pte(ulong, void *, ulonglong); +static ulong arm64_vmalloc_start(void); +static int arm64_is_task_addr(ulong); +static int arm64_dis_filter(ulong, char *, unsigned int); +static void arm64_cmd_mach(void); +static void arm64_display_machine_stats(void); +static int arm64_get_smp_cpus(void); +static void arm64_clear_machdep_cache(void); +static int arm64_in_alternate_stack(int, ulong); +static int arm64_get_kvaddr_ranges(struct vaddr_range *); +static int arm64_get_crash_notes(void); + +/* + * Do all necessary machine-specific setup here. This is called several times + * during initialization. + */ +void +arm64_init(int when) +{ + ulong value; + +#if defined(__x86_64__) + if (ACTIVE()) + error(FATAL, "compiled for the ARM64 architecture\n"); +#endif + + switch (when) { + case PRE_SYMTAB: + machdep->machspec = &arm64_machine_specific; + machdep->process_elf_notes = process_elf64_notes; + if (pc->flags & KERNEL_DEBUG_QUERY) + return; + machdep->verify_paddr = generic_verify_paddr; + machdep->verify_symbol = arm64_verify_symbol; + if (machdep->cmdline_args[0]) + arm64_parse_cmdline_args(); + break; + + case PRE_GDB: + if (kernel_symbol_exists("swapper_pg_dir") && + kernel_symbol_exists("idmap_pg_dir")) { + value = symbol_value("swapper_pg_dir") - + symbol_value("idmap_pg_dir"); + machdep->pagesize = value / 2; + } else + machdep->pagesize = memory_page_size(); /* host */ + machdep->pageshift = ffs(machdep->pagesize) - 1; + machdep->pageoffset = machdep->pagesize - 1; + machdep->pagemask = ~((ulonglong)machdep->pageoffset); + switch (machdep->pagesize) + { + case 4096: + machdep->flags |= VM_L3_4K; + machdep->ptrs_per_pgd = PTRS_PER_PGD_L3_4K; + if ((machdep->pgd = + (char *)malloc(PTRS_PER_PGD_L3_4K * 8)) == NULL) + error(FATAL, "cannot malloc pgd space."); + if ((machdep->pmd = + (char *)malloc(PTRS_PER_PMD_L3_4K * 8)) == NULL) + error(FATAL, "cannot malloc pmd space."); + if ((machdep->ptbl = + (char *)malloc(PTRS_PER_PTE_L3_4K * 8)) == NULL) + error(FATAL, "cannot malloc ptbl space."); + machdep->pud = NULL; /* not used */ + break; + + case 65536: + machdep->flags |= VM_L2_64K; + machdep->ptrs_per_pgd = PTRS_PER_PGD_L2_64K; + if ((machdep->pgd = + (char *)malloc(PTRS_PER_PGD_L2_64K * 8)) == NULL) + error(FATAL, "cannot malloc pgd space."); + if ((machdep->ptbl = + (char *)malloc(PTRS_PER_PTE_L2_64K * 8)) == NULL) + error(FATAL, "cannot malloc ptbl space."); + machdep->pmd = NULL; /* not used */ + machdep->pud = NULL; /* not used */ + break; + + default: + error(FATAL, "invalid/unknown page size: %d\n", + machdep->pagesize); + } + machdep->last_pud_read = 0; /* not used */ + machdep->last_pgd_read = 0; + machdep->last_pmd_read = 0; + machdep->last_ptbl_read = 0; + machdep->clear_machdep_cache = arm64_clear_machdep_cache; + + machdep->stacksize = ARM64_STACK_SIZE; + machdep->machspec->userspace_top = ARM64_USERSPACE_TOP; + machdep->machspec->page_offset = ARM64_PAGE_OFFSET; + machdep->machspec->vmalloc_start_addr = ARM64_VMALLOC_START; + machdep->machspec->vmalloc_end = ARM64_VMALLOC_END; + machdep->machspec->vmemmap_vaddr = ARM64_VMEMMAP_VADDR; + machdep->machspec->vmemmap_end = ARM64_VMEMMAP_END; + machdep->machspec->modules_vaddr = ARM64_MODULES_VADDR; + machdep->machspec->modules_end = ARM64_MODULES_END; + + machdep->kvbase = ARM64_VMALLOC_START; + machdep->identity_map_base = ARM64_PAGE_OFFSET; + + arm64_calc_phys_offset(); + + machdep->uvtop = arm64_uvtop; + machdep->kvtop = arm64_kvtop; + machdep->is_kvaddr = generic_is_kvaddr; + machdep->is_uvaddr = generic_is_uvaddr; + machdep->eframe_search = arm64_eframe_search; + machdep->back_trace = arm64_back_trace_cmd; + machdep->in_alternate_stack = arm64_in_alternate_stack; + machdep->processor_speed = arm64_processor_speed; + machdep->get_task_pgd = arm64_get_task_pgd; + machdep->get_stack_frame = arm64_get_stack_frame; + machdep->get_stackbase = generic_get_stackbase; + machdep->get_stacktop = generic_get_stacktop; + machdep->translate_pte = arm64_translate_pte; + machdep->memory_size = generic_memory_size; + machdep->vmalloc_start = arm64_vmalloc_start; + machdep->get_kvaddr_ranges = arm64_get_kvaddr_ranges; + machdep->is_task_addr = arm64_is_task_addr; + machdep->dis_filter = arm64_dis_filter; + machdep->cmd_mach = arm64_cmd_mach; + machdep->get_smp_cpus = arm64_get_smp_cpus; + machdep->line_number_hooks = NULL; + machdep->value_to_symbol = generic_machdep_value_to_symbol; + machdep->dump_irq = generic_dump_irq; + machdep->show_interrupts = generic_show_interrupts; + machdep->get_irq_affinity = generic_get_irq_affinity; + machdep->dumpfile_init = NULL; + machdep->verify_line_number = NULL; + machdep->init_kernel_pgd = arm64_init_kernel_pgd; + break; + + case POST_GDB: + machdep->section_size_bits = _SECTION_SIZE_BITS; + machdep->max_physmem_bits = _MAX_PHYSMEM_BITS; + if (THIS_KERNEL_VERSION >= LINUX(3,10,0)) { + machdep->machspec->pte_protnone = PTE_PROT_NONE_3_10; + machdep->machspec->pte_file = PTE_FILE_3_10; + } else { + machdep->machspec->pte_protnone = PTE_PROT_NONE; + machdep->machspec->pte_file = PTE_FILE; + } + + if (symbol_exists("irq_desc")) + ARRAY_LENGTH_INIT(machdep->nr_irqs, irq_desc, + "irq_desc", NULL, 0); + else if (kernel_symbol_exists("nr_irqs")) + get_symbol_data("nr_irqs", sizeof(unsigned int), + &machdep->nr_irqs); + + if (!machdep->hz) + machdep->hz = 100; + + arm64_stackframe_init(); + break; + + case POST_VM: + /* + * crash_notes contains machine specific information about the + * crash. In particular, it contains CPU registers at the time + * of the crash. We need this information to extract correct + * backtraces from the panic task. + */ + if (!ACTIVE() && !arm64_get_crash_notes()) + error(WARNING, "could not retrieve crash_notes\n"); + + break; + + case LOG_ONLY: + machdep->machspec = &arm64_machine_specific; + machdep->identity_map_base = ARM64_PAGE_OFFSET; + arm64_calc_phys_offset(); + break; + } +} + +/* + * Accept or reject a symbol from the kernel namelist. + */ +static int +arm64_verify_symbol(const char *name, ulong value, char type) +{ +// if (STREQ(name, "swapper_pg_dir")) +// machdep->flags |= KSYMS_START; +// +// if (!name || !strlen(name) || !(machdep->flags & KSYMS_START)) +// return FALSE; +// +// if (STREQ(name, "$a") || STREQ(name, "$n") || STREQ(name, "$d")) +// return FALSE; +// +// if (STREQ(name, "PRRR") || STREQ(name, "NMRR")) +// return FALSE; +// +// if ((type == 'A') && STRNEQ(name, "__crc_")) +// return FALSE; +// +// if (CRASHDEBUG(8) && name && strlen(name)) +// fprintf(fp, "%08lx %s\n", value, name); +// + NOT_IMPLEMENTED(WARNING); + return TRUE; +} + + +void +arm64_dump_machdep_table(ulong arg) +{ + const struct machine_specific *ms; + int others, i; + + others = 0; + fprintf(fp, " flags: %lx (", machdep->flags); + if (machdep->flags & KSYMS_START) + fprintf(fp, "%sKSYMS_START", others++ ? "|" : ""); + if (machdep->flags & PHYS_OFFSET) + fprintf(fp, "%sPHYS_OFFSET", others++ ? "|" : ""); + if (machdep->flags & VM_L2_64K) + fprintf(fp, "%sVM_L2_64K", others++ ? "|" : ""); + if (machdep->flags & VM_L3_4K) + fprintf(fp, "%sVM_L3_4K", others++ ? "|" : ""); + fprintf(fp, ")\n"); + + fprintf(fp, " kvbase: %lx\n", machdep->kvbase); + fprintf(fp, " identity_map_base: %lx\n", machdep->kvbase); + fprintf(fp, " pagesize: %d\n", machdep->pagesize); + fprintf(fp, " pageshift: %d\n", machdep->pageshift); + fprintf(fp, " pagemask: %lx\n", (ulong)machdep->pagemask); + fprintf(fp, " pageoffset: %lx\n", machdep->pageoffset); + fprintf(fp, " stacksize: %ld\n", machdep->stacksize); + fprintf(fp, " hz: %d\n", machdep->hz); + fprintf(fp, " mhz: %ld\n", machdep->mhz); + fprintf(fp, " memsize: %lld (0x%llx)\n", + (ulonglong)machdep->memsize, (ulonglong)machdep->memsize); + fprintf(fp, " bits: %d\n", machdep->bits); + fprintf(fp, " nr_irqs: %d\n", machdep->nr_irqs); + fprintf(fp, " eframe_search: arm64_eframe_search()\n"); + fprintf(fp, " back_trace: arm64_back_trace_cmd()\n"); + fprintf(fp, " in_alternate_stack: arm64_in_alternate_stack()\n"); + fprintf(fp, " processor_speed: arm64_processor_speed()\n"); + fprintf(fp, " uvtop: arm64_uvtop()->%s()\n", + machdep->flags & VM_L3_4K ? + "arm64_vtop_3level_4k" : "arm64_vtop_2level_64k"); + fprintf(fp, " kvtop: arm64_kvtop()->%s()\n", + machdep->flags & VM_L3_4K ? + "arm64_vtop_3level_4k" : "arm64_vtop_2level_64k"); + fprintf(fp, " get_task_pgd: arm64_get_task_pgd()\n"); + fprintf(fp, " dump_irq: generic_dump_irq()\n"); + fprintf(fp, " get_stack_frame: arm64_get_stack_frame()\n"); + fprintf(fp, " get_stackbase: generic_get_stackbase()\n"); + fprintf(fp, " get_stacktop: generic_get_stacktop()\n"); + fprintf(fp, " translate_pte: arm64_translate_pte()\n"); + fprintf(fp, " memory_size: generic_memory_size()\n"); + fprintf(fp, " vmalloc_start: arm64_vmalloc_start()\n"); + fprintf(fp, " get_kvaddr_ranges: arm64_get_kvaddr_ranges()\n"); + fprintf(fp, " is_task_addr: arm64_is_task_addr()\n"); + fprintf(fp, " verify_symbol: arm64_verify_symbol()\n"); + fprintf(fp, " dis_filter: arm64_dis_filter()\n"); + fprintf(fp, " cmd_mach: arm64_cmd_mach()\n"); + fprintf(fp, " get_smp_cpus: arm64_get_smp_cpus()\n"); + fprintf(fp, " is_kvaddr: generic_is_kvaddr()\n"); + fprintf(fp, " is_uvaddr: generic_is_uvaddr()\n"); + fprintf(fp, " value_to_symbol: generic_machdep_value_to_symbol()\n"); + fprintf(fp, " init_kernel_pgd: arm64_init_kernel_pgd\n"); + fprintf(fp, " verify_paddr: generic_verify_paddr()\n"); + fprintf(fp, " show_interrupts: generic_show_interrupts()\n"); + fprintf(fp, " get_irq_affinity: generic_get_irq_affinity()\n"); + fprintf(fp, " dumpfile_init: (not used)\n"); + fprintf(fp, " process_elf_notes: process_elf64_notes()\n"); + fprintf(fp, " verify_line_number: (not used)\n"); + + fprintf(fp, " xendump_p2m_create: (n/a)\n"); + fprintf(fp, "xen_kdump_p2m_create: (n/a)\n"); + fprintf(fp, " xendump_panic_task: (n/a)\n"); + fprintf(fp, " get_xendump_regs: (n/a)\n"); + fprintf(fp, " line_number_hooks: (not used)\n"); + fprintf(fp, " last_pud_read: (not used)\n"); + fprintf(fp, " last_pgd_read: %lx\n", machdep->last_pgd_read); + fprintf(fp, " last_pmd_read: "); + if (PAGESIZE() == 65536) + fprintf(fp, "(not used)\n"); + else + fprintf(fp, "%lx\n", machdep->last_pmd_read); + fprintf(fp, " last_ptbl_read: %lx\n", machdep->last_ptbl_read); + fprintf(fp, " clear_machdep_cache: arm64_clear_machdep_cache()\n"); + fprintf(fp, " pgd: %lx\n", (ulong)machdep->pgd); + fprintf(fp, " pmd: %lx\n", (ulong)machdep->pmd); + fprintf(fp, " ptbl: %lx\n", (ulong)machdep->ptbl); + fprintf(fp, " ptrs_per_pgd: %d\n", machdep->ptrs_per_pgd); + fprintf(fp, " section_size_bits: %ld\n", machdep->section_size_bits); + fprintf(fp, " max_physmem_bits: %ld\n", machdep->max_physmem_bits); + fprintf(fp, " sections_per_root: %ld\n", machdep->sections_per_root); + + for (i = 0; i < MAX_MACHDEP_ARGS; i++) { + fprintf(fp, " cmdline_args[%d]: %s\n", + i, machdep->cmdline_args[i] ? + machdep->cmdline_args[i] : "(unused)"); + } + + ms = machdep->machspec; + + fprintf(fp, " machspec: %lx\n", (ulong)ms); + fprintf(fp, " userspace_top: %016lx\n", ms->userspace_top); + fprintf(fp, " page_offset: %016lx\n", ms->page_offset); + fprintf(fp, " vmalloc_start_addr: %016lx\n", ms->vmalloc_start_addr); + fprintf(fp, " vmalloc_end: %016lx\n", ms->vmalloc_end); + fprintf(fp, " modules_vaddr: %016lx\n", ms->modules_vaddr); + fprintf(fp, " modules_end: %016lx\n", ms->modules_end); + fprintf(fp, " vmemmap_vaddr: %016lx\n", ms->vmemmap_vaddr); + fprintf(fp, " phys_offset: %lx\n", ms->phys_offset); + fprintf(fp, "__exception_text_start: %lx\n", ms->__exception_text_start); + fprintf(fp, " __exception_text_end: %lx\n", ms->__exception_text_end); + fprintf(fp, " panic_task_regs: %lx\n", (ulong)ms->panic_task_regs); + fprintf(fp, " pte_protnone: %lx\n", ms->pte_protnone); + fprintf(fp, " pte_file: %lx\n", ms->pte_file); +} + + +/* + * Parse machine dependent command line arguments. + * + * Force the phys_offset address via: + * + * --machdep phys_offset=
+ */ +static void +arm64_parse_cmdline_args(void) +{ + int index, i, c, err; + char *arglist[MAXARGS]; + char buf[BUFSIZE]; + char *p; + ulong value = 0; + + for (index = 0; index < MAX_MACHDEP_ARGS; index++) { + if (!machdep->cmdline_args[index]) + break; + + if (!strstr(machdep->cmdline_args[index], "=")) { + error(WARNING, "ignoring --machdep option: %x\n", + machdep->cmdline_args[index]); + continue; + } + + strcpy(buf, machdep->cmdline_args[index]); + + for (p = buf; *p; p++) { + if (*p == ',') + *p = ' '; + } + + c = parse_line(buf, arglist); + + for (i = 0; i < c; i++) { + err = 0; + + if (STRNEQ(arglist[i], "phys_offset=")) { + int megabytes = FALSE; + int flags = RETURN_ON_ERROR | QUIET; + + if ((LASTCHAR(arglist[i]) == 'm') || + (LASTCHAR(arglist[i]) == 'M')) { + LASTCHAR(arglist[i]) = NULLCHAR; + megabytes = TRUE; + } + + p = arglist[i] + strlen("phys_offset="); + if (strlen(p)) { + if (megabytes) + value = dtol(p, flags, &err); + else + value = htol(p, flags, &err); + } + + if (!err) { + if (megabytes) + value = MEGABYTES(value); + + machdep->machspec->phys_offset = value; + + error(NOTE, + "setting phys_offset to: 0x%lx\n", + machdep->machspec->phys_offset); + + machdep->flags |= PHYS_OFFSET; + continue; + } + } + + error(WARNING, "ignoring --machdep option: %s\n", + arglist[i]); + } + } +} + + +static void +arm64_calc_phys_offset(void) +{ + struct machine_specific *ms = machdep->machspec; + ulong phys_offset; + + if (machdep->flags & PHYS_OFFSET) /* --machdep override */ + return; + + /* + * Next determine suitable value for phys_offset. User can override this + * by passing valid '--machdep phys_offset=' option. + */ + ms->phys_offset = 0; + + if (ACTIVE()) { + char buf[BUFSIZE]; + char *p1; + int errflag; + FILE *fp; + + if ((fp = fopen("/proc/iomem", "r")) == NULL) + return; + + /* + * Memory regions are sorted in ascending order. We take the + * first region which should be correct for most uses. + */ + errflag = 1; + while (fgets(buf, BUFSIZE, fp)) { + if (strstr(buf, ": System RAM")) { + clean_line(buf); + errflag = 0; + break; + } + } + fclose(fp); + + if (errflag) + return; + + if (!(p1 = strstr(buf, "-"))) + return; + + *p1 = NULLCHAR; + + phys_offset = htol(buf, RETURN_ON_ERROR | QUIET, &errflag); + if (errflag) + return; + + ms->phys_offset = phys_offset; + } else if (DISKDUMP_DUMPFILE() && diskdump_phys_base(&phys_offset)) { + ms->phys_offset = phys_offset; + } else if (KDUMP_DUMPFILE() && arm64_kdump_phys_base(&phys_offset)) { + ms->phys_offset = phys_offset; + } else { + error(WARNING, + "phys_offset cannot be determined from the dumpfile.\n"); + error(CONT, + "Using default value of 0. If this is not correct, then try\n"); + error(CONT, + "using the command line option: --machdep phys_offset=\n"); + } + + if (CRASHDEBUG(1)) + fprintf(fp, "using %lx as phys_offset\n", ms->phys_offset); +} + + +/* + * Borrow the 32-bit ARM functionality. + */ +static int +arm64_kdump_phys_base(ulong *phys_offset) +{ + return arm_kdump_phys_base(phys_offset); +} + +static void +arm64_init_kernel_pgd(void) +{ + int i; + ulong value; + + if (!kernel_symbol_exists("init_mm") || + !readmem(symbol_value("init_mm") + OFFSET(mm_struct_pgd), KVADDR, + &value, sizeof(void *), "init_mm.pgd", RETURN_ON_ERROR)) { + if (kernel_symbol_exists("swapper_pg_dir")) + value = symbol_value("swapper_pg_dir"); + else { + error(WARNING, "cannot determine kernel pgd location\n"); + return; + } + } + + for (i = 0; i < NR_CPUS; i++) + vt->kernel_pgd[i] = value; +} + +static int +arm64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose) +{ + ulong kernel_pgd; + + if (!IS_KVADDR(kvaddr)) + return FALSE; + + if (!vt->vmalloc_start) { + *paddr = VTOP(kvaddr); + return TRUE; + } + + if (!IS_VMALLOC_ADDR(kvaddr)) { + *paddr = VTOP(kvaddr); + if (!verbose) + return TRUE; + } + + kernel_pgd = vt->kernel_pgd[0]; + + switch (machdep->flags & (VM_L2_64K|VM_L3_4K)) + { + case VM_L2_64K: + return arm64_vtop_2level_64k(kernel_pgd, kvaddr, paddr, verbose); + case VM_L3_4K: + return arm64_vtop_3level_4k(kernel_pgd, kvaddr, paddr, verbose); + default: + return FALSE; + } +} + +static int +arm64_uvtop(struct task_context *tc, ulong uvaddr, physaddr_t *paddr, int verbose) +{ + ulong user_pgd; + + readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, + &user_pgd, sizeof(long), "user pgd", FAULT_ON_ERROR); + + switch (machdep->flags & (VM_L2_64K|VM_L3_4K)) + { + case VM_L2_64K: + return arm64_vtop_2level_64k(user_pgd, uvaddr, paddr, verbose); + case VM_L3_4K: + return arm64_vtop_3level_4k(user_pgd, uvaddr, paddr, verbose); + default: + return FALSE; + } +} + +static int +arm64_vtop_2level_64k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) +{ + ulong *pgd_base, *pgd_ptr, pgd_val; + ulong *pte_base, *pte_ptr, pte_val; + + if (verbose) + fprintf(fp, "PAGE DIRECTORY: %lx\n", pgd); + + pgd_base = (ulong *)pgd; + FILL_PGD(pgd_base, KVADDR, PTRS_PER_PGD_L2_64K * sizeof(ulong)); + pgd_ptr = pgd_base + (((vaddr) >> PGDIR_SHIFT_L2_64K) & (PTRS_PER_PGD_L2_64K - 1)); + pgd_val = ULONG(machdep->pgd + PAGEOFFSET(pgd_ptr)); + if (verbose) + fprintf(fp, " PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val); + if (!pgd_val) + goto no_page; + + /* + * #define __PAGETABLE_PUD_FOLDED + * #define __PAGETABLE_PMD_FOLDED + */ + + pte_base = (ulong *)PTOV(pgd_val & PHYS_MASK & (s32)machdep->pagemask); + FILL_PTBL(pte_base, KVADDR, PTRS_PER_PTE_L2_64K * sizeof(ulong)); + pte_ptr = pte_base + (((vaddr) >> machdep->pageshift) & (PTRS_PER_PTE_L2_64K - 1)); + pte_val = ULONG(machdep->ptbl + PAGEOFFSET(pte_ptr)); + if (verbose) + fprintf(fp, " PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val); + if (!pte_val) + goto no_page; + + if (pte_val & PTE_VALID) { + *paddr = (PAGEBASE(pte_val) & PHYS_MASK) + PAGEOFFSET(vaddr); + if (verbose) { + fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(*paddr)); + arm64_translate_pte(pte_val, 0, 0); + } + } else { + if (verbose) { + fprintf(fp, "\n"); + arm64_translate_pte(pte_val, 0, 0); + } + goto no_page; + } + + return TRUE; +no_page: + return FALSE; +} + +static int +arm64_vtop_3level_4k(ulong pgd, ulong vaddr, physaddr_t *paddr, int verbose) +{ + ulong *pgd_base, *pgd_ptr, pgd_val; + ulong *pmd_base, *pmd_ptr, pmd_val; + ulong *pte_base, *pte_ptr, pte_val; + + if (verbose) + fprintf(fp, "PAGE DIRECTORY: %lx\n", pgd); + + pgd_base = (ulong *)pgd; + FILL_PGD(pgd_base, KVADDR, PTRS_PER_PGD_L3_4K * sizeof(ulong)); + pgd_ptr = pgd_base + (((vaddr) >> PGDIR_SHIFT_L3_4K) & (PTRS_PER_PGD_L3_4K - 1)); + pgd_val = ULONG(machdep->pgd + PAGEOFFSET(pgd_ptr)); + if (verbose) + fprintf(fp, " PGD: %lx => %lx\n", (ulong)pgd_ptr, pgd_val); + if (!pgd_val) + goto no_page; + + /* + * #define __PAGETABLE_PUD_FOLDED + */ + + pmd_base = (ulong *)PTOV(pgd_val & PHYS_MASK & (s32)machdep->pagemask); + FILL_PMD(pmd_base, KVADDR, PTRS_PER_PMD_L3_4K * sizeof(ulong)); + pmd_ptr = pmd_base + (((vaddr) >> PMD_SHIFT_L3_4K) & (PTRS_PER_PMD_L3_4K - 1)); + pmd_val = ULONG(machdep->pmd + PAGEOFFSET(pmd_ptr)); + if (verbose) + fprintf(fp, " PMD: %lx => %lx\n", (ulong)pmd_ptr, pmd_val); + if (!pmd_val) + goto no_page; + + pte_base = (ulong *)PTOV(pmd_val & PHYS_MASK & (s32)machdep->pagemask); + FILL_PTBL(pte_base, KVADDR, PTRS_PER_PTE_L3_4K * sizeof(ulong)); + pte_ptr = pte_base + (((vaddr) >> machdep->pageshift) & (PTRS_PER_PTE_L3_4K - 1)); + pte_val = ULONG(machdep->ptbl + PAGEOFFSET(pte_ptr)); + if (verbose) + fprintf(fp, " PTE: %lx => %lx\n", (ulong)pte_ptr, pte_val); + if (!pte_val) + goto no_page; + + if (pte_val & PTE_VALID) { + *paddr = (PAGEBASE(pte_val) & PHYS_MASK) + PAGEOFFSET(vaddr); + if (verbose) { + fprintf(fp, " PAGE: %lx\n\n", PAGEBASE(*paddr)); + arm64_translate_pte(pte_val, 0, 0); + } + } else { + if (verbose) { + fprintf(fp, "\n"); + arm64_translate_pte(pte_val, 0, 0); + } + goto no_page; + } + + return TRUE; +no_page: + return FALSE; +} + +static ulong +arm64_get_task_pgd(ulong task) +{ + struct task_context *tc; + ulong pgd; + + if ((tc = task_to_context(task)) && + readmem(tc->mm_struct + OFFSET(mm_struct_pgd), KVADDR, + &pgd, sizeof(long), "user pgd", RETURN_ON_ERROR)) + return pgd; + else + return NO_TASK; +} + +static ulong +arm64_processor_speed(void) +{ + return 0; +}; + + +/* + * Gather and verify all of the backtrace requirements. + */ +static void +arm64_stackframe_init(void) +{ + long task_struct_thread; + long thread_struct_context; + long context_sp, context_pc, context_fp; + + STRUCT_SIZE_INIT(note_buf, "note_buf_t"); + STRUCT_SIZE_INIT(elf_prstatus, "elf_prstatus"); + MEMBER_OFFSET_INIT(elf_prstatus_pr_pid, "elf_prstatus", "pr_pid"); + MEMBER_OFFSET_INIT(elf_prstatus_pr_reg, "elf_prstatus", "pr_reg"); + + machdep->machspec->__exception_text_start = + symbol_value("__exception_text_start"); + machdep->machspec->__exception_text_end = + symbol_value("__exception_text_end"); + + task_struct_thread = MEMBER_OFFSET("task_struct", "thread"); + thread_struct_context = MEMBER_OFFSET("thread_struct", "context"); + + if ((task_struct_thread == INVALID_OFFSET) || + (thread_struct_context == INVALID_OFFSET)) { + error(INFO, + "cannot determine task_struct.thread.context offset\n"); + return; + } + + /* + * Pay for the convenience of using a hardcopy of a kernel structure. + */ + if (offsetof(struct arm64_stackframe, sp) != + MEMBER_OFFSET("stackframe", "sp")) { + error(INFO, "builtin stackframe.sp offset incorrect!\n"); + return; + } + if (offsetof(struct arm64_stackframe, fp) != + MEMBER_OFFSET("stackframe", "fp")) { + error(INFO, "builtin stackframe.fp offset incorrect!\n"); + return; + } + if (offsetof(struct arm64_stackframe, pc) != + MEMBER_OFFSET("stackframe", "pc")) { + error(INFO, "builtin stackframe.pc offset incorrect!\n"); + return; + } + + context_sp = MEMBER_OFFSET("cpu_context", "sp"); + context_fp = MEMBER_OFFSET("cpu_context", "fp"); + context_pc = MEMBER_OFFSET("cpu_context", "pc"); + if (context_sp == INVALID_OFFSET) { + error(INFO, "cannot determine cpu_context.sp offset\n"); + return; + } + if (context_fp == INVALID_OFFSET) { + error(INFO, "cannot determine cpu_context.fp offset\n"); + return; + } + if (context_pc == INVALID_OFFSET) { + error(INFO, "cannot determine cpu_context.pc offset\n"); + return; + } + ASSIGN_OFFSET(task_struct_thread_context_sp) = + task_struct_thread + thread_struct_context + context_sp; + ASSIGN_OFFSET(task_struct_thread_context_fp) = + task_struct_thread + thread_struct_context + context_fp; + ASSIGN_OFFSET(task_struct_thread_context_pc) = + task_struct_thread + thread_struct_context + context_pc; +} + +static int arm64_eframe_search(struct bt_info *bt) +{ + return (NOT_IMPLEMENTED(FATAL)); +} + +static int +arm64_in_exception_text(ulong ptr) +{ + struct machine_specific *ms = machdep->machspec; + + return((ptr >= ms->__exception_text_start) && + (ptr < ms->__exception_text_end)); +} + +static void +arm64_print_stackframe_entry(struct bt_info *bt, int level, struct arm64_stackframe *frame) +{ + char *name, *name_plus_offset; + ulong symbol_offset; + struct syment *sp; + struct load_module *lm; + char buf[BUFSIZE]; + + name = closest_symbol(frame->pc); + name_plus_offset = NULL; + + if (bt->flags & BT_SYMBOL_OFFSET) { + sp = value_search(frame->pc, &symbol_offset); + if (sp && symbol_offset) + name_plus_offset = + value_to_symstr(frame->pc, buf, bt->radix); + } + + fprintf(fp, "%s#%d [%8lx] %s at %lx", level < 10 ? " " : "", level, + frame->sp, name_plus_offset ? name_plus_offset : name, frame->pc); + + if (module_symbol(frame->pc, NULL, &lm, NULL, 0)) + fprintf(fp, " [%s]", lm->mod_name); + + fprintf(fp, "\n"); +} + +static int arm64_unwind_frame(struct bt_info *bt, struct arm64_stackframe *frame) +{ + unsigned long high, low, fp; + unsigned long stack_mask; + + stack_mask = (unsigned long)(ARM64_STACK_SIZE) - 1; + fp = frame->fp; + + low = frame->sp; + high = (low + stack_mask) & ~(stack_mask); + + if (fp < low || fp > high || fp & 0xf) + return FALSE; + + frame->sp = fp + 0x10; + frame->fp = *(unsigned long *)(fp); + frame->pc = *(unsigned long *)(fp + 8); + + return TRUE; +} + +static void arm64_back_trace_cmd(struct bt_info *bt) +{ + struct arm64_stackframe stackframe; + int level; + + if (BT_REFERENCE_CHECK(bt)) + option_not_supported('R'); + + if (bt->flags & BT_USER_SPACE) { + fprintf(fp, "#0 [user space]\n"); + return; + } + + stackframe.sp = bt->stkptr; + stackframe.pc = bt->instptr; + stackframe.fp = bt->frameptr; + + level = 0; + while (1) { + bt->instptr = stackframe.pc; + + arm64_print_stackframe_entry(bt, level, &stackframe); + + if (!arm64_unwind_frame(bt, &stackframe)) + break; + + if (arm64_in_exception_text(bt->instptr)) + fprintf(fp, "TBD: dump exception frame: pt_regs @ stackframe.sp\n"); + + level++; + } +} + +static int +arm64_get_dumpfile_stackframe(struct bt_info *bt, struct arm64_stackframe *frame) +{ + struct machine_specific *ms = machdep->machspec; + struct arm64_pt_regs *ptregs; + + if (!ms->panic_task_regs) + return FALSE; + + ptregs = &ms->panic_task_regs[bt->tc->processor]; + frame->sp = ptregs->sp; + frame->pc = ptregs->pc; + frame->fp = ptregs->regs[29]; + + if (!is_kernel_text(frame->pc) && + in_user_stack(bt->tc->task, frame->sp)) + bt->flags |= BT_USER_SPACE; + + return TRUE; +} + +static int +arm64_get_stackframe(struct bt_info *bt, struct arm64_stackframe *frame) +{ + if (!fill_task_struct(bt->task)) + return FALSE; + + frame->sp = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_sp)); + frame->pc = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_pc)); + frame->fp = ULONG(tt->task_struct + OFFSET(task_struct_thread_context_fp)); + + return TRUE; +} + +static void +arm64_get_stack_frame(struct bt_info *bt, ulong *pcp, ulong *spp) +{ + int ret; + struct arm64_stackframe stackframe; + + if (DUMPFILE() && is_task_active(bt->task)) + ret = arm64_get_dumpfile_stackframe(bt, &stackframe); + else + ret = arm64_get_stackframe(bt, &stackframe); + + if (!ret) { + error(WARNING, + "cannot get stackframe for task %lx\n", bt->task); + return; + } + + bt->frameptr = stackframe.fp; + if (pcp) + *pcp = stackframe.pc; + if (spp) + *spp = stackframe.sp; +} + +/* + * Translate a PTE, returning TRUE if the page is present. + * If a physaddr pointer is passed in, don't print anything. + */ +static int +arm64_translate_pte(ulong pte, void *physaddr, ulonglong unused) +{ + int c, others, len1, len2, len3; + ulong paddr; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char buf3[BUFSIZE]; + char ptebuf[BUFSIZE]; + char physbuf[BUFSIZE]; + char *arglist[MAXARGS]; + int page_present; + + paddr = pte & PHYS_MASK & (s32)machdep->pagemask; + page_present = pte & (PTE_VALID | machdep->machspec->pte_protnone); + + if (physaddr) { + *((ulong *)physaddr) = paddr; + return page_present; + } + + sprintf(ptebuf, "%lx", pte); + len1 = MAX(strlen(ptebuf), strlen("PTE")); + fprintf(fp, "%s ", mkstring(buf1, len1, CENTER|LJUST, "PTE")); + + if (!page_present && (pte & PTE_FILE)) { + swap_location(pte, buf1); + if ((c = parse_line(buf1, arglist)) != 3) + error(FATAL, "cannot determine swap location\n"); + + len2 = MAX(strlen(arglist[0]), strlen("SWAP")); + len3 = MAX(strlen(arglist[2]), strlen("OFFSET")); + + fprintf(fp, "%s %s\n", + mkstring(buf2, len2, CENTER|LJUST, "SWAP"), + mkstring(buf3, len3, CENTER|LJUST, "OFFSET")); + + strcpy(buf2, arglist[0]); + strcpy(buf3, arglist[2]); + fprintf(fp, "%s %s %s\n", + mkstring(ptebuf, len1, CENTER|RJUST, NULL), + mkstring(buf2, len2, CENTER|RJUST, NULL), + mkstring(buf3, len3, CENTER|RJUST, NULL)); + + return page_present; + } + + sprintf(physbuf, "%lx", paddr); + len2 = MAX(strlen(physbuf), strlen("PHYSICAL")); + fprintf(fp, "%s ", mkstring(buf1, len2, CENTER|LJUST, "PHYSICAL")); + + fprintf(fp, "FLAGS\n"); + + fprintf(fp, "%s %s ", + mkstring(ptebuf, len1, CENTER|RJUST, NULL), + mkstring(physbuf, len2, CENTER|RJUST, NULL)); + fprintf(fp, "("); + others = 0; + + if (pte) { + if (pte & PTE_VALID) + fprintf(fp, "%sVALID", others++ ? "|" : ""); + if (THIS_KERNEL_VERSION >= LINUX(3,10,0)) { + if (pte & machdep->machspec->pte_file) + fprintf(fp, "%sFILE", others++ ? "|" : ""); + if (pte & machdep->machspec->pte_protnone) + fprintf(fp, "%sPROTNONE", others++ ? "|" : ""); + } else { + if (pte & machdep->machspec->pte_protnone) + fprintf(fp, "%sPROTNONE", others++ ? "|" : ""); + if (pte & machdep->machspec->pte_file) + fprintf(fp, "%sFILE", others++ ? "|" : ""); + } + if (pte & PTE_USER) + fprintf(fp, "%sUSER", others++ ? "|" : ""); + if (pte & PTE_RDONLY) + fprintf(fp, "%sRDONLY", others++ ? "|" : ""); + if (pte & PTE_SHARED) + fprintf(fp, "%sSHARED", others++ ? "|" : ""); + if (pte & PTE_AF) + fprintf(fp, "%sAF", others++ ? "|" : ""); + if (pte & PTE_NG) + fprintf(fp, "%sNG", others++ ? "|" : ""); + if (pte & PTE_PXN) + fprintf(fp, "%sPXN", others++ ? "|" : ""); + if (pte & PTE_UXN) + fprintf(fp, "%sUXN", others++ ? "|" : ""); + if (pte & PTE_DIRTY) + fprintf(fp, "%sDIRTY", others++ ? "|" : ""); + if (pte & PTE_SPECIAL) + fprintf(fp, "%sSPECIAL", others++ ? "|" : ""); + } else { + fprintf(fp, "no mapping"); + } + + fprintf(fp, ")\n"); + + return (page_present); +} + +static ulong +arm64_vmalloc_start(void) +{ + return ARM64_VMALLOC_START; +} + +/* + * Not so accurate since thread_info introduction. + */ +static int +arm64_is_task_addr(ulong task) +{ + if (tt->flags & THREAD_INFO) + return IS_KVADDR(task); + else + return (IS_KVADDR(task) && (ALIGNED_STACK_OFFSET(task) == 0)); +} + +/* + * Filter dissassembly output if the output radix is not gdb's default 10 + */ +static int +arm64_dis_filter(ulong vaddr, char *inbuf, unsigned int output_radix) +{ + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char *colon, *p1; + int argc; + char *argv[MAXARGS]; + ulong value; + + if (!inbuf) + return TRUE; + + console("IN: %s", inbuf); + + colon = strstr(inbuf, ":"); + + if (colon) { + sprintf(buf1, "0x%lx <%s>", vaddr, + value_to_symstr(vaddr, buf2, output_radix)); + sprintf(buf2, "%s%s", buf1, colon); + strcpy(inbuf, buf2); + } + + strcpy(buf1, inbuf); + argc = parse_line(buf1, argv); + + if ((FIRSTCHAR(argv[argc-1]) == '<') && + (LASTCHAR(argv[argc-1]) == '>')) { + p1 = rindex(inbuf, '<'); + while ((p1 > inbuf) && !STRNEQ(p1, " 0x")) + p1--; + + if (!STRNEQ(p1, " 0x")) + return FALSE; + p1++; + + if (!extract_hex(p1, &value, NULLCHAR, TRUE)) + return FALSE; + + sprintf(buf1, "0x%lx <%s>\n", value, + value_to_symstr(value, buf2, output_radix)); + + sprintf(p1, "%s", buf1); + } + + console(" %s", inbuf); + + return TRUE; +} + +/* + * Machine dependent command. + */ +static void +arm64_cmd_mach(void) +{ + int c; + + while ((c = getopt(argcnt, args, "cm")) != -1) { + switch (c) { + case 'c': + case 'm': + option_not_supported(c); + break; + + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + arm64_display_machine_stats(); +} + +static void +arm64_display_machine_stats(void) +{ + struct new_utsname *uts; + char buf[BUFSIZE]; + ulong mhz; + + uts = &kt->utsname; + + fprintf(fp, " MACHINE TYPE: %s\n", uts->machine); + fprintf(fp, " MEMORY SIZE: %s\n", get_memory_size(buf)); + fprintf(fp, " CPUS: %d\n", get_cpus_to_display()); + if ((mhz = machdep->processor_speed())) + fprintf(fp, " PROCESSOR SPEED: %ld Mhz\n", mhz); + fprintf(fp, " HZ: %d\n", machdep->hz); + fprintf(fp, " PAGE SIZE: %d\n", PAGESIZE()); + fprintf(fp, "KERNEL VIRTUAL BASE: %lx\n", ARM64_PAGE_OFFSET); + fprintf(fp, "KERNEL VMALLOC BASE: %lx\n", ARM64_VMALLOC_START); + fprintf(fp, "KERNEL MODULES BASE: %lx\n", ARM64_MODULES_VADDR); + fprintf(fp, " KERNEL STACK SIZE: %ld\n", STACKSIZE()); +} + +static int +arm64_get_smp_cpus(void) +{ + return MAX(get_cpus_online(), get_highest_cpu_online()+1); +} + + +/* + * Retrieve task registers for the time of the crash. + */ +static int +arm64_get_crash_notes(void) +{ + struct machine_specific *ms = machdep->machspec; + ulong crash_notes; + Elf64_Nhdr *note; + ulong offset; + char *buf, *p; + ulong *notes_ptrs; + ulong i; + + if (!symbol_exists("crash_notes")) + return FALSE; + + crash_notes = symbol_value("crash_notes"); + + notes_ptrs = (ulong *)GETBUF(kt->cpus*sizeof(notes_ptrs[0])); + + /* + * Read crash_notes for the first CPU. crash_notes are in standard ELF + * note format. + */ + if (!readmem(crash_notes, KVADDR, ¬es_ptrs[kt->cpus-1], + sizeof(notes_ptrs[kt->cpus-1]), "crash_notes", RETURN_ON_ERROR)) { + error(WARNING, "cannot read crash_notes\n"); + FREEBUF(notes_ptrs); + return FALSE; + } + + if (symbol_exists("__per_cpu_offset")) { + /* + * Add __per_cpu_offset for each cpu to form the notes pointer. + */ + for (i = 0; icpus; i++) + notes_ptrs[i] = notes_ptrs[kt->cpus-1] + kt->__per_cpu_offset[i]; + } + + buf = GETBUF(SIZE(note_buf)); + + if (!(ms->panic_task_regs = malloc(kt->cpus * sizeof(struct arm64_pt_regs)))) + error(FATAL, "cannot malloc panic_task_regs space\n"); + + for (i = 0; i < kt->cpus; i++) { + + if (!readmem(notes_ptrs[i], KVADDR, buf, SIZE(note_buf), + "note_buf_t", RETURN_ON_ERROR)) { + error(WARNING, "failed to read note_buf_t\n"); + goto fail; + } + + /* + * Do some sanity checks for this note before reading registers from it. + */ + note = (Elf64_Nhdr *)buf; + p = buf + sizeof(Elf64_Nhdr); + + if (note->n_type != NT_PRSTATUS) { + error(WARNING, "invalid note (n_type != NT_PRSTATUS)\n"); + goto fail; + } + if (p[0] != 'C' || p[1] != 'O' || p[2] != 'R' || p[3] != 'E') { + error(WARNING, "invalid note (name != \"CORE\"\n"); + goto fail; + } + + /* + * Find correct location of note data. This contains elf_prstatus + * structure which has registers etc. for the crashed task. + */ + offset = sizeof(Elf64_Nhdr); + offset = roundup(offset + note->n_namesz, 4); + p = buf + offset; /* start of elf_prstatus */ + + BCOPY(p + OFFSET(elf_prstatus_pr_reg), &ms->panic_task_regs[i], + sizeof(struct arm64_pt_regs)); + } + + FREEBUF(buf); + FREEBUF(notes_ptrs); + return TRUE; + +fail: + FREEBUF(buf); + FREEBUF(notes_ptrs); + free(ms->panic_task_regs); + ms->panic_task_regs = NULL; + return FALSE; +} + +static void +arm64_clear_machdep_cache(void) { + /* + * TBD: probably not necessary... + */ + return; +} + +static int +arm64_in_alternate_stack(int cpu, ulong stkptr) +{ + NOT_IMPLEMENTED(INFO); + return FALSE; +} + + +static int +compare_kvaddr(const void *v1, const void *v2) +{ + struct vaddr_range *r1, *r2; + + r1 = (struct vaddr_range *)v1; + r2 = (struct vaddr_range *)v2; + + return (r1->start < r2->start ? -1 : + r1->start == r2->start ? 0 : 1); +} + +static int +arm64_get_kvaddr_ranges(struct vaddr_range *vrp) +{ + int cnt; + + cnt = 0; + + vrp[cnt].type = KVADDR_UNITY_MAP; + vrp[cnt].start = machdep->machspec->page_offset; + vrp[cnt++].end = vt->high_memory; + + vrp[cnt].type = KVADDR_VMALLOC; + vrp[cnt].start = machdep->machspec->vmalloc_start_addr; + vrp[cnt++].end = last_vmalloc_address(); + + if (st->mods_installed) { + vrp[cnt].type = KVADDR_MODULES; + vrp[cnt].start = lowest_module_address(); + vrp[cnt++].end = roundup(highest_module_address(), + PAGESIZE()); + } + + if (machdep->flags & VMEMMAP) { + vrp[cnt].type = KVADDR_VMEMMAP; + vrp[cnt].start = machdep->machspec->vmemmap_vaddr; + vrp[cnt++].end = vt->node_table[vt->numnodes-1].mem_map + + (vt->node_table[vt->numnodes-1].size * SIZE(page)); + } + + qsort(vrp, cnt, sizeof(struct vaddr_range), compare_kvaddr); + + return cnt; +} + +/* + * Include both vmalloc'd, module and vmemmap address space as VMALLOC space. + */ +int +arm64_IS_VMALLOC_ADDR(ulong vaddr) +{ + return ((vaddr >= ARM64_VMALLOC_START && vaddr <= ARM64_VMALLOC_END) || + ((machdep->flags & VMEMMAP) && + (vaddr >= ARM64_VMEMMAP_VADDR && vaddr <= ARM64_VMEMMAP_END)) || + (vaddr >= ARM64_MODULES_VADDR && vaddr <= ARM64_MODULES_END)); +} + +#endif /* ARM64 */ + diff --git a/cmdline.c b/cmdline.c new file mode 100644 index 00000000..d532767f --- /dev/null +++ b/cmdline.c @@ -0,0 +1,2508 @@ +/* cmdline.c - core analysis suite + * + * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2013 David Anderson + * Copyright (C) 2002-2013 Red Hat, Inc. 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. + */ + +#include "defs.h" + +static void restore_sanity(void); +static void restore_ifile_sanity(void); +static int pseudo_command(char *); +static void check_special_handling(char *); +static int is_shell_script(char *); +static void list_aliases(char *); +static int allocate_alias(int); +static int alias_exists(char *); +static void resolve_aliases(void); +static int setup_redirect(int); +static int output_command_to_pids(void); +static void set_my_tty(void); +static char *signame(int); +static int setup_stdpipe(void); +static void wait_for_children(ulong); +#define ZOMBIES_ONLY (1) +#define ALL_CHILDREN (2) +int shell_command(char *); +static void modify_orig_line(char *, struct args_input_file *); +static void modify_expression_arg(char *, char **, struct args_input_file *); +static int verify_args_input_file(char *); + +#define READLINE_LIBRARY + +#include +#include +#include + +static void readline_init(void); + +static struct alias_data alias_head = { 0 }; + +void +process_command_line(void) +{ + /* + * Restore normal environment, clearing out any excess baggage + * piled up by the previous command. + */ + restore_sanity(); + fp = stdout; + BZERO(pc->command_line, BUFSIZE); + + if (!(pc->flags & + (READLINE|SILENT|CMDLINE_IFILE|RCHOME_IFILE|RCLOCAL_IFILE))) + fprintf(fp, "%s", pc->prompt); + fflush(fp); + + /* + * Input can come from five possible sources: + * + * 1. an .rc file located in the user's HOME directory. + * 2. an .rc file located in the current directory. + * 3. an input file that was designated by the -i flag at + * program invocation. + * 4. from a terminal. + * 5. from a pipe, if stdin is a pipe rather than a terminal. + * + * But first, handle the interruption of an input file caused + * by a FATAL error in one of its commands. + * + */ + if (pc->ifile_in_progress) { + switch (pc->ifile_in_progress) + { + case RCHOME_IFILE: + pc->flags |= INIT_IFILE|RCHOME_IFILE; + sprintf(pc->command_line, "< %s/.%src", + pc->home, pc->program_name); + break; + case RCLOCAL_IFILE: + sprintf(pc->command_line, "< .%src", pc->program_name); + pc->flags |= INIT_IFILE|RCLOCAL_IFILE; + break; + case CMDLINE_IFILE: + sprintf(pc->command_line, "< %s", pc->input_file); + pc->flags |= INIT_IFILE|CMDLINE_IFILE; + break; + case RUNTIME_IFILE: + sprintf(pc->command_line, "%s", pc->runtime_ifile_cmd); + pc->flags |= IFILE_ERROR; + break; + default: + error(FATAL, "invalid input file\n"); + } + } else if (pc->flags & RCHOME_IFILE) { + sprintf(pc->command_line, "< %s/.%src", + pc->home, pc->program_name); + pc->flags |= INIT_IFILE; + } else if (pc->flags & RCLOCAL_IFILE) { + sprintf(pc->command_line, "< .%src", pc->program_name); + pc->flags |= INIT_IFILE; + } else if (pc->flags & CMDLINE_IFILE) { + sprintf(pc->command_line, "< %s", pc->input_file); + pc->flags |= INIT_IFILE; + } else if (pc->flags & TTY) { + if (!(pc->readline = readline(pc->prompt))) { + args[0] = NULL; + fprintf(fp, "\n"); + return; + } + + strcpy(pc->command_line, pc->readline); + free(pc->readline); + + clean_line(pc->command_line); + pseudo_command(pc->command_line); + strcpy(pc->orig_line, pc->command_line); + + if (strlen(pc->command_line) && !iscntrl(pc->command_line[0])) + add_history(pc->command_line); + + check_special_handling(pc->command_line); + } else { + if (fgets(pc->command_line, BUFSIZE-1, stdin) == NULL) + clean_exit(1); + clean_line(pc->command_line); + strcpy(pc->orig_line, pc->command_line); + } + + /* + * First clean out all linefeeds and leading/trailing spaces. + * Then substitute aliases for the real thing they represent. + */ + clean_line(pc->command_line); + resolve_aliases(); + + /* + * Setup output redirection based upon the command line itself or + * based upon the default scrolling behavior, if any. + */ + + switch (setup_redirect(FROM_COMMAND_LINE)) + { + case REDIRECT_NOT_DONE: + case REDIRECT_TO_STDPIPE: + case REDIRECT_TO_PIPE: + case REDIRECT_TO_FILE: + break; + + case REDIRECT_SHELL_ESCAPE: + case REDIRECT_SHELL_COMMAND: + case REDIRECT_FAILURE: + RESTART(); + break; + } + + /* + * Setup the global argcnt and args[] array for use by everybody + * during the life of this command. + */ + argcnt = parse_line(pc->command_line, args); +} + + +/* + * Allow input file redirection without having to put a space between + * the < and the filename. Allow the "pointer-to" asterisk to "touch" + * the structure/union name. + */ +static void +check_special_handling(char *s) +{ + char local[BUFSIZE]; + + strcpy(local, s); + + if ((local[0] == '*') && (!whitespace(local[1]))) { + sprintf(s, "* %s", &local[1]); + return; + } + + if ((local[0] == '<') && (!whitespace(local[1]))) { + sprintf(s, "< %s", &local[1]); + return; + } +} + + +/* + * At this point the only pseudo commands are the "r" (repeat) and + * the "h" (history) command: + * + * 1. an "r" alone, or "!!" along, just means repeat the last command. + * 2. an "r" followed by a number, means repeat that command from the + * history table. + * 3. an "r" followed by one or more non-decimal characters means to + * seek back until a line-beginning match is found. + * 4. an "h" alone, or a string beginning with "hi", means history. + */ +static int +pseudo_command(char *input) +{ + int i; + HIST_ENTRY *entry; + int idx, found; + char *p; + + clean_line(input); + + /* + * Just dump all commands that have been entered to date. + */ + if (STREQ(input, "h") || STRNEQ(input, "hi")) { + dump_history(); + pc->command_line[0] = NULLCHAR; + return TRUE; + } + + if (STREQ(input, "r") || STREQ(input, "!!")) { + if (!history_offset) + error(FATAL, "no commands entered!\n"); + entry = history_get(history_offset); + strcpy(input, entry->line); + fprintf(fp, "%s%s\n", pc->prompt, input); + return TRUE; + } + + if ((input[0] == 'r') && decimal(&input[1], 0)) { + if (!history_offset) + error(FATAL, "no commands entered!\n"); + p = &input[1]; + goto rerun; + } + + + if (STRNEQ(input, "r ")) { + if (!history_offset) + error(FATAL, "no commands entered!\n"); + + p = first_nonspace(&input[1]); +rerun: + if (decimal(p, 0)) { + idx = atoi(p); + if (idx == 0) + goto invalid_repeat_request; + if (idx > history_offset) + error(FATAL, "command %d not entered yet!\n", + idx); + entry = history_get(idx); + strcpy(input, entry->line); + fprintf(fp, "%s%s\n", pc->prompt, input); + return TRUE; + } + + idx = -1; + found = FALSE; + + for (i = history_offset; i > 0; i--) { + entry = history_get(i); + if (STRNEQ(entry->line, p)) { + found = TRUE; + break; + } + } + + if (found) { + strcpy(input, entry->line); + fprintf(fp, "%s%s\n", pc->prompt, input); + return TRUE; + } + +invalid_repeat_request: + fprintf(fp, "invalid repeat request: %s\n", input); + strcpy(input, ""); + return TRUE; + } + + return FALSE; +} + +/* + * Dump the history table in first-to-last chronological order. + */ +void +dump_history(void) +{ + int i; + HIST_ENTRY **the_history; + HIST_ENTRY *entry; + + if (!history_offset) + error(FATAL, "no commands entered!\n"); + + the_history = history_list(); + + for (i = 0; i < history_offset; i++) { + entry = the_history[i]; + fprintf(fp, "[%d] %s\n", i+1, entry->line); + } +} + +/* + * Pager arguments. + */ + +static char *less_argv[5] = { + "/usr/bin/less", + "-E", + "-X", + "-Ps -- MORE -- forward\\: , or j backward\\: b or k quit\\: q", + NULL +}; + +static char *more_argv[2] = { + "/bin/more", + NULL +}; + +static char **CRASHPAGER_argv = NULL; + +int +CRASHPAGER_valid(void) +{ + int i, c; + char *env, *CRASHPAGER_buf; + char *arglist[MAXARGS]; + + if (CRASHPAGER_argv) + return TRUE; + + if (!(env = getenv("CRASHPAGER"))) + return FALSE; + + if (strstr(env, "|") || strstr(env, "<") || strstr(env, ">")) { + error(INFO, + "CRASHPAGER ignored: contains invalid character: \"%s\"\n", + env); + return FALSE; + } + + if ((CRASHPAGER_buf = (char *)malloc(strlen(env)+1)) == NULL) + return FALSE; + + strcpy(CRASHPAGER_buf, env); + + if (!(c = parse_line(CRASHPAGER_buf, arglist)) || + !file_exists(arglist[0], NULL) || access(arglist[0], X_OK) || + !(CRASHPAGER_argv = (char **)malloc(sizeof(char *) * (c+1)))) { + free(CRASHPAGER_buf); + if (strlen(env)) + error(INFO, + "CRASHPAGER ignored: \"%s\"\n", env); + return FALSE; + } + + for (i = 0; i < c; i++) + CRASHPAGER_argv[i] = arglist[i]; + CRASHPAGER_argv[i] = NULL; + + return TRUE; +} + +/* + * Set up a command string buffer for error/help output. + */ +char * +setup_scroll_command(void) +{ + char *buf; + long i, len; + + if (!(pc->flags & SCROLL)) + return NULL; + + switch (pc->scroll_command) + { + case SCROLL_LESS: + buf = GETBUF(strlen(less_argv[0])+1); + strcpy(buf, less_argv[0]); + break; + case SCROLL_MORE: + buf = GETBUF(strlen(more_argv[0])+1); + strcpy(buf, more_argv[0]); + break; + case SCROLL_CRASHPAGER: + for (i = len = 0; CRASHPAGER_argv[i]; i++) + len += strlen(CRASHPAGER_argv[i])+1; + + buf = GETBUF(len); + + for (i = 0; CRASHPAGER_argv[i]; i++) { + sprintf(&buf[strlen(buf)], "%s%s", + i ? " " : "", + CRASHPAGER_argv[i]); + } + break; + default: + return NULL; + } + + return buf; +} + +/* + * Parse the command line for pipe or redirect characters: + * + * 1. if a "|" character is found, popen() what comes after it, and + * modify the contents of the global "fp" FILE pointer. + * 2. if one or two ">" characters are found, fopen() the filename that + * follows, and modify the contents of the global "fp" FILE pointer. + * + * Care is taken to segregate: + * + * 1. expressions encompassed by parentheses, or + * 2. strings encompassed by apostrophes. + * + * When either of the above are in affect, no redirection is done. + * + * Lastly, if no redirection is requested by the user on the command line, + * output is passed to the default scrolling command, which is popen()'d + * and again, the contents of the global "fp" FILE pointer is modified. + * This default behavior is not performed if the command is coming from + * an input file, nor if scrolling has been turned off. + */ +static int +setup_redirect(int origin) +{ + char *p, which; + int append; + int expression; + int string; + int ret ATTRIBUTE_UNUSED; + FILE *pipe; + FILE *ofile; + + pc->redirect = origin; + pc->eoc_index = 0; + + p = pc->command_line; + + if (STREQ(p, "|") || STREQ(p, "!")) { + ret = system("/bin/sh"); + pc->redirect |= REDIRECT_SHELL_ESCAPE; + return REDIRECT_SHELL_ESCAPE; + } + + if (FIRSTCHAR(p) == '|' || FIRSTCHAR(p) == '!') + pc->redirect |= REDIRECT_SHELL_COMMAND; + + expression = string = FALSE; + + while (*p) { + if (*p == '(') + expression = TRUE; + if (*p == ')') + expression = FALSE; + + if (*p == '"') + string = !string; + + if (!(expression || string) && + ((*p == '|') || (*p == '!'))) { + which = *p; + *p = NULLCHAR; + pc->eoc_index = p - pc->command_line; + p++; + p = strip_beginning_whitespace(p); + + if (!strlen(p)) { + error(INFO, "no shell command after '%c'\n", + which); + pc->redirect |= REDIRECT_FAILURE; + return REDIRECT_FAILURE; + } + + if (LASTCHAR(p) == '|') + error(FATAL_RESTART, "pipe to nowhere?\n"); + + if (pc->redirect & REDIRECT_SHELL_COMMAND) + return shell_command(p); + + if ((pipe = popen(p, "w")) == NULL) { + error(INFO, "cannot open pipe\n"); + pc->redirect |= REDIRECT_FAILURE; + return REDIRECT_FAILURE; + } + setbuf(pipe, NULL); + + switch (origin) + { + case FROM_COMMAND_LINE: + fp = pc->pipe = pipe; + break; + + case FROM_INPUT_FILE: + fp = pc->ifile_pipe = pipe; + break; + } + + if (strstr(p, "|")) { + p = rindex(p, '|') + 1; + p = first_nonspace(p); + pc->redirect |= REDIRECT_MULTI_PIPE; + } + + strcpy(pc->pipe_command, p); + null_first_space(pc->pipe_command); + + pc->redirect |= REDIRECT_TO_PIPE; + + if (!(pc->redirect & REDIRECT_SHELL_COMMAND)) { + if ((pc->pipe_pid = output_command_to_pids())) + pc->redirect |= REDIRECT_PID_KNOWN; + else + error(FATAL_RESTART, + "pipe operation failed\n"); + } + + return REDIRECT_TO_PIPE; + } + + if (!(expression || string) && (*p == '>') && + !((p > pc->command_line) && (*(p-1) == '-'))) { + append = FALSE; + + *p = NULLCHAR; + pc->eoc_index = p - pc->command_line; + if (*(p+1) == '>') { + append = TRUE; + *p = NULLCHAR; + p++; + } + p++; + p = strip_beginning_whitespace(p); + + if (!strlen(p)) { + error(INFO, "no file name after %s\n", + append ? ">>" : ">"); + pc->redirect |= REDIRECT_FAILURE; + return REDIRECT_FAILURE; + } + + if (pc->flags & IFILE_ERROR) + append = TRUE; + + if ((ofile = + fopen(p, append ? "a+" : "w+")) == NULL) { + error(INFO, "unable to open %s\n", p); + pc->redirect = REDIRECT_FAILURE; + return REDIRECT_FAILURE; + } + setbuf(ofile, NULL); + + switch (origin) + { + case FROM_COMMAND_LINE: + fp = pc->ofile = ofile; + break; + + case FROM_INPUT_FILE: + fp = pc->ifile_ofile = ofile; + break; + } + + pc->redirect |= REDIRECT_TO_FILE; + return REDIRECT_TO_FILE; + } + + p++; + } + + if ((origin == FROM_COMMAND_LINE) && (pc->flags & TTY) && + (pc->flags & SCROLL) && pc->scroll_command) { + if (!strlen(pc->command_line) || + STREQ(pc->command_line, "q") || + STREQ(pc->command_line, "Q") || + STREQ(pc->command_line, "exit") || + STRNEQ(pc->command_line, "<")) { + pc->redirect |= REDIRECT_NOT_DONE; + return REDIRECT_NOT_DONE; + } + + if (!setup_stdpipe()) { + error(INFO, "cannot open pipe\n"); + pc->redirect |= REDIRECT_FAILURE; + return REDIRECT_FAILURE; + } + fp = pc->stdpipe; + + pc->redirect |= REDIRECT_TO_STDPIPE; + + switch (pc->scroll_command) + { + case SCROLL_LESS: + strcpy(pc->pipe_command, less_argv[0]); + break; + case SCROLL_MORE: + strcpy(pc->pipe_command, more_argv[0]); + break; + case SCROLL_CRASHPAGER: + strcpy(pc->pipe_command, CRASHPAGER_argv[0]); + break; + } + + return REDIRECT_TO_STDPIPE; + } + + pc->redirect |= REDIRECT_NOT_DONE; + + return REDIRECT_NOT_DONE; +} + +void +debug_redirect(char *s) +{ + int others; + int alive; + + others = 0; + console("%s: (", s); + if (pc->redirect & FROM_COMMAND_LINE) + console("%sFROM_COMMAND_LINE", others++ ? "|" : ""); + if (pc->redirect & FROM_INPUT_FILE) + console("%sFROM_INPUT_FILE", others++ ? "|" : ""); + if (pc->redirect & REDIRECT_NOT_DONE) + console("%sREDIRECT_NOT_DONE", others++ ? "|" : ""); + if (pc->redirect & REDIRECT_TO_PIPE) + console("%sREDIRECT_TO_PIPE", others++ ? "|" : ""); + if (pc->redirect & REDIRECT_TO_STDPIPE) + console("%sREDIRECT_TO_STDPIPE", others++ ? "|" : ""); + if (pc->redirect & REDIRECT_TO_FILE) + console("%sREDIRECT_TO_FILE", others++ ? "|" : ""); + if (pc->redirect & REDIRECT_FAILURE) + console("%sREDIRECT_FAILURE", others++ ? "|" : ""); + if (pc->redirect & REDIRECT_SHELL_ESCAPE) + console("%sREDIRECT_SHELL_ESCAPE", others++ ? "|" : ""); + if (pc->redirect & REDIRECT_SHELL_COMMAND) + console("%sREDIRECT_SHELL_COMMAND", others++ ? "|" : ""); + if (pc->redirect & REDIRECT_PID_KNOWN) + console("%sREDIRECT_PID_KNOWN", others++ ? "|" : ""); + if (pc->redirect & REDIRECT_MULTI_PIPE) + console("%sREDIRECT_MULTI_PIPE", others++ ? "|" : ""); + console(")\n"); + + if (pc->pipe_pid || strlen(pc->pipe_command)) { + if (pc->pipe_pid && PID_ALIVE(pc->pipe_pid)) + alive = TRUE; + else + alive = FALSE; + console("pipe_pid: %d (%s) pipe_command: %s\n", + pc->pipe_pid, + alive ? "alive" : "dead", + pc->pipe_command); + } +} + +/* + * Determine whether the pid receiving the current piped output is still + * alive. + * + * NOTE: This routine returns TRUE by default, and only returns FALSE if + * the pipe_pid exists *and* it's known to have died. Therefore the + * caller must be cognizant of pc->pipe_pid or pc->stdpipe_pid. + */ +int +output_open(void) +{ + int waitstatus, waitret; + + if (!(pc->flags & TTY)) + return TRUE; + + switch (pc->redirect & PIPE_OPTIONS) + { + case (REDIRECT_TO_STDPIPE|FROM_COMMAND_LINE): + waitret = waitpid(pc->stdpipe_pid, &waitstatus, WNOHANG); + if ((waitret == pc->stdpipe_pid) || (waitret == -1)) + return FALSE; + break; + + case (REDIRECT_TO_PIPE|FROM_INPUT_FILE): + if (pc->curcmd_flags & REPEAT) + break; + /* FALLTHROUGH */ + case (REDIRECT_TO_PIPE|FROM_COMMAND_LINE): + switch (pc->redirect & (REDIRECT_MULTI_PIPE)) + { + case REDIRECT_MULTI_PIPE: + if (!PID_ALIVE(pc->pipe_pid)) + return FALSE; + break; + + default: + waitret = waitpid(pc->pipe_pid, &waitstatus, WNOHANG); + if (waitret == pc->pipe_pid) + return FALSE; + if (waitret == -1) { /* intervening sh */ + if (!PID_ALIVE(pc->pipe_pid)) + return FALSE; + } + break; + } + break; + + default: + break; + } + + return TRUE; +} + + +/* + * Determine the pids of the current popen'd shell and output command. + * This is all done using /proc; the ps kludge at the bottom of this + * routine is legacy, and should only get executed if /proc doesn't exist. + */ +static int +output_command_to_pids(void) +{ + DIR *dirp; + struct dirent *dp; + FILE *stp; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char lookfor[BUFSIZE]; + char *pid, *name, *status, *p_pid, *pgrp; + char *arglist[MAXARGS]; + int argc; + FILE *pipe; + int retries, shell_has_exited; + + retries = 0; + shell_has_exited = FALSE; + pc->pipe_pid = pc->pipe_shell_pid = 0; + sprintf(lookfor, "(%s)", pc->pipe_command); + stall(1000); +retry: + if (is_directory("/proc") && (dirp = opendir("/proc"))) { + for (dp = readdir(dirp); dp && !pc->pipe_pid; + dp = readdir(dirp)) { + if (!decimal(dp->d_name, 0)) + continue; + sprintf(buf1, "/proc/%s/stat", dp->d_name); + if (file_exists(buf1, NULL) && + (stp = fopen(buf1, "r"))) { + if (fgets(buf2, BUFSIZE, stp)) { + pid = strtok(buf2, " "); + name = strtok(NULL, " "); + status = strtok(NULL, " "); + p_pid = strtok(NULL, " "); + pgrp = strtok(NULL, " "); + if (STREQ(name, "(sh)") && + (atoi(p_pid) == getpid())) { + pc->pipe_shell_pid = atoi(pid); + if (STREQ(status, "Z")) + shell_has_exited = TRUE; + } + if (STREQ(name, lookfor) && + ((atoi(p_pid) == getpid()) || + (atoi(p_pid) == pc->pipe_shell_pid) + || (atoi(pgrp) == getpid()))) { + pc->pipe_pid = atoi(pid); + console( + "FOUND[%d] (%d->%d->%d) %s %s p_pid: %s pgrp: %s\n", + retries, getpid(), + pc->pipe_shell_pid, + pc->pipe_pid, + name, status, p_pid, pgrp); + } + } + fclose(stp); + } + } + closedir(dirp); + } + + if (!pc->pipe_pid && !shell_has_exited && + ((retries++ < 10) || pc->pipe_shell_pid)) { + stall(1000); + goto retry; + } + + console("getpid: %d pipe_shell_pid: %d pipe_pid: %d\n", + getpid(), pc->pipe_shell_pid, pc->pipe_pid); + + if (pc->pipe_pid) + return pc->pipe_pid; + + sprintf(buf1, "ps -ft %s", pc->my_tty); + console("%s: ", buf1); + + if ((pipe = popen(buf1, "r")) == NULL) { + error(INFO, "cannot determine output pid\n"); + return 0; + } + + while (fgets(buf1, BUFSIZE, pipe)) { + argc = parse_line(buf1, arglist); + if ((argc >= 8) && + STREQ(arglist[7], pc->pipe_command) && + STRNEQ(pc->my_tty, arglist[5])) { + pc->pipe_pid = atoi(arglist[1]); + break; + } + } + pclose(pipe); + console("%d\n", pc->pipe_pid); + + return pc->pipe_pid; +} + +/* + * Close straggling, piped-to, output commands. + */ +void +close_output(void) +{ + if ((pc->flags & TTY) && + (pc->pipe_pid || strlen(pc->pipe_command)) && + output_open()) + kill(pc->pipe_pid, 9); +} + +/* + * Initialize what's needed for the command line: + * + * 1. termios structures for raw and cooked terminal mode. + * 2. set up SIGINT and SIGPIPE handlers for aborted commands. + * 3. set up the command history table. + * 4. create the prompt string. + */ +void +cmdline_init(void) +{ + int fd = 0; + + /* + * Stash a copy of the original termios setup. + * Build a raw version for quick use for each command entry. + */ + if (isatty(fileno(stdin)) && ((fd = open("/dev/tty", O_RDONLY)) >= 0)) { + if (tcgetattr(fd, &pc->termios_orig) == -1) + error(FATAL, "tcgetattr /dev/tty: %s\n", + strerror(errno)); + + if (tcgetattr(fd, &pc->termios_raw) == -1) + error(FATAL, "tcgetattr /dev/tty: %s\n", + strerror(errno)); + + close(fd); + + pc->termios_raw.c_lflag &= ~ECHO & ~ICANON; + pc->termios_raw.c_cc[VMIN] = (char)1; + pc->termios_raw.c_cc[VTIME] = (char)0; + + restore_sanity(); + + pc->flags |= TTY; + set_my_tty(); + + SIGACTION(SIGINT, restart, &pc->sigaction, NULL); + readline_init(); + } + else { + if (fd < 0) + error(INFO, "/dev/tty: %s\n", strerror(errno)); + if (!(pc->flags & SILENT)) + fprintf(fp, "NOTE: stdin: not a tty\n\n"); + fflush(fp); + pc->flags &= ~TTY; + } + + SIGACTION(SIGPIPE, SIG_IGN, &pc->sigaction, NULL); + + set_command_prompt(NULL); +} + + +/* + * Create and stash the original prompt, but allow changes during runtime. + */ +void +set_command_prompt(char *new_prompt) +{ + static char *orig_prompt = NULL; + + if (!orig_prompt) { + if (!(orig_prompt = (char *)malloc(strlen(pc->program_name)+3))) + error(FATAL, "cannot malloc prompt string\n"); + sprintf(orig_prompt, "%s> ", pc->program_name); + } + + if (new_prompt) + pc->prompt = new_prompt; + else + pc->prompt = orig_prompt; +} + +/* + * SIGINT, SIGPIPE, and SIGSEGV handler. + * Signal number 0 is sent for a generic restart. + */ +#define MAX_RECURSIVE_SIGNALS (10) +#define MAX_SIGINTS_ACCEPTED (3) + +void +restart(int sig) +{ + static int in_restart = 0; + + console("restart (%s) %s\n", signame(sig), + pc->flags & IN_GDB ? "(in gdb)" : "(in crash)"); + + if (sig == SIGUSR2) + clean_exit(1); + + if (pc->flags & IN_RESTART) { + fprintf(stderr, + "\nembedded signal received (%s): recursive restart call\n", + signame(sig)); + if (++in_restart < MAX_RECURSIVE_SIGNALS) + return; + fprintf(stderr, "bailing out...\n"); + clean_exit(1); + } else { + pc->flags |= IN_RESTART; + in_restart = 0; + } + + switch (sig) + { + case SIGSEGV: + fflush(fp); + fprintf(stderr, " \n", + pc->flags & IN_GDB ? " in gdb" : ""); + case 0: + case SIGPIPE: + restore_sanity(); + break; + + case SIGINT: + SIGACTION(SIGINT, restart, &pc->sigaction, NULL); + pc->flags |= _SIGINT_; + pc->sigint_cnt++; + pc->flags &= ~IN_RESTART; + if (pc->sigint_cnt == MAX_SIGINTS_ACCEPTED) { + restore_sanity(); + break; + } + return; + + default: + fprintf(stderr, "unexpected signal received: %s\n", + signame(sig)); + restore_sanity(); + close_output(); + break; + } + + fprintf(fp, "\n"); + + pc->flags &= ~(IN_FOREACH|IN_GDB|IN_RESTART); + longjmp(pc->main_loop_env, 1); +} + +/* + * Return a signal name string, or a number if the signal is not listed. + */ +static char * +signame(int sig) +{ + static char sigbuf[20]; + + switch (sig) + { + case SIGINT: + sprintf(sigbuf, "SIGINT-%d", pc->sigint_cnt+1); + return sigbuf; + case SIGPIPE: + return "SIGPIPE"; + case SIGSEGV: + return "SIGSEGV"; + default: + sprintf(sigbuf, "%d", sig); + return sigbuf; + } +} + +/* + * Restore the program environment to the state it was in before the + * last command was executed: + * + * 1. close all temporarily opened pipes and output files. + * 2. set the terminal back to normal cooked mode. + * 3. free all temporary buffers. + * 4. restore the last known output radix. + */ +static void +restore_sanity(void) +{ + int fd, waitstatus; + struct extension_table *ext; + struct command_table_entry *cp; + + if (pc->stdpipe) { + close(fileno(pc->stdpipe)); + pc->stdpipe = NULL; + if (pc->stdpipe_pid && PID_ALIVE(pc->stdpipe_pid)) { + while (!waitpid(pc->stdpipe_pid, &waitstatus, WNOHANG)) + stall(1000); + } + pc->stdpipe_pid = 0; + } + if (pc->pipe) { + close(fileno(pc->pipe)); + pc->pipe = NULL; + console("wait for redirect %d->%d to finish...\n", + pc->pipe_shell_pid, pc->pipe_pid); + if (pc->pipe_pid) + while (PID_ALIVE(pc->pipe_pid)) { + waitpid(pc->pipe_pid, &waitstatus, WNOHANG); + stall(1000); + } + if (pc->pipe_shell_pid) + while (PID_ALIVE(pc->pipe_shell_pid)) { + waitpid(pc->pipe_shell_pid, + &waitstatus, WNOHANG); + stall(1000); + } + pc->pipe_pid = 0; + } + if (pc->ifile_pipe) { + fflush(pc->ifile_pipe); + close(fileno(pc->ifile_pipe)); + pc->ifile_pipe = NULL; + if (pc->pipe_pid && + ((pc->redirect & (PIPE_OPTIONS|REDIRECT_PID_KNOWN)) == + (FROM_INPUT_FILE|REDIRECT_TO_PIPE|REDIRECT_PID_KNOWN))) { + console("wait for redirect %d->%d to finish...\n", + pc->pipe_shell_pid, pc->pipe_pid); + while (PID_ALIVE(pc->pipe_pid)) { + waitpid(pc->pipe_pid, &waitstatus, WNOHANG); + stall(1000); + } + if (pc->pipe_shell_pid) + while (PID_ALIVE(pc->pipe_shell_pid)) { + waitpid(pc->pipe_shell_pid, + &waitstatus, WNOHANG); + stall(1000); + } + if (pc->redirect & (REDIRECT_MULTI_PIPE)) + wait_for_children(ALL_CHILDREN); + } + } + + if (pc->ofile) { + fclose(pc->ofile); + pc->ofile = NULL; + } + if (pc->ifile_ofile) { + fclose(pc->ifile_ofile); + pc->ifile_ofile = NULL; + } + + if (pc->ifile) { + fclose(pc->ifile); + pc->ifile = NULL; + } + + if (pc->args_ifile) { + fclose(pc->args_ifile); + pc->args_ifile = NULL; + } + + if (pc->tmpfile) + close_tmpfile(); + + if (pc->tmpfile2) + close_tmpfile2(); + + if (pc->cmd_cleanup) + pc->cmd_cleanup(pc->cmd_cleanup_arg); + + if (pc->flags & TTY) { + if ((fd = open("/dev/tty", O_RDONLY)) < 0) { + console("/dev/tty: %s\n", strerror(errno)); + clean_exit(1); + } + + if (tcsetattr(fd, TCSANOW, &pc->termios_orig) == -1) + error(FATAL, "tcsetattr /dev/tty: %s\n", + strerror(errno)); + + close(fd); + } + + wait_for_children(ZOMBIES_ONLY); + + pc->flags &= ~(INIT_IFILE|RUNTIME_IFILE|IFILE_ERROR|_SIGINT_|PLEASE_WAIT); + pc->sigint_cnt = 0; + pc->redirect = 0; + pc->pipe_command[0] = NULLCHAR; + pc->pipe_pid = 0; + pc->pipe_shell_pid = 0; + pc->sbrk = sbrk(0); + if ((pc->curcmd_flags & (UD2A_INSTRUCTION|BAD_INSTRUCTION)) == + (UD2A_INSTRUCTION|BAD_INSTRUCTION)) + error(WARNING, "A (bad) instruction was noted in last disassembly.\n" + " Use \"dis -b [number]\" to set/restore the number of\n" + " encoded bytes to skip after a ud2a (BUG) instruction.\n"); + pc->curcmd_flags = 0; + pc->curcmd_private = 0; + + restore_gdb_sanity(); + + free_all_bufs(); + + /* + * Clear the structure cache references -- no-ops if DUMPFILE(). + */ + clear_task_cache(); + clear_machdep_cache(); + clear_swap_info_cache(); + clear_file_cache(); + clear_dentry_cache(); + clear_inode_cache(); + clear_vma_cache(); + clear_active_set(); + + if (kt->ikconfig_flags & IKCONFIG_LOADED) + read_in_kernel_config(IKCFG_FREE); + + /* + * Call the cleanup() function of any extension. + */ + for (ext = extension_table; ext; ext = ext->next) { + for (cp = ext->command_table; cp->name; cp++) { + if (cp->flags & CLEANUP) + (*cp->func)(); + } + } + + if (CRASHDEBUG(5)) { + dump_filesys_table(0); + dump_vma_cache(0); + dump_text_value_cache(0); + } + + if (REMOTE()) + remote_clear_pipeline(); + + hq_close(); +} + +/* + * Similar to above, but only called in between each command that is + * read from an input file. + */ +static void +restore_ifile_sanity(void) +{ + int fd; + + pc->flags &= ~IFILE_ERROR; + + if (pc->ifile_pipe) { + close(fileno(pc->ifile_pipe)); + pc->ifile_pipe = NULL; + } + + if (pc->ifile_ofile) { + fclose(pc->ifile_ofile); + pc->ifile_ofile = NULL; + } + + if (pc->flags & TTY) { + if ((fd = open("/dev/tty", O_RDONLY)) < 0) { + console("/dev/tty: %s\n", strerror(errno)); + clean_exit(1); + } + + if (tcsetattr(fd, TCSANOW, &pc->termios_orig) == -1) + error(FATAL, "tcsetattr /dev/tty: %s\n", + strerror(errno)); + + close(fd); + } + + if (pc->tmpfile2) { + close_tmpfile2(); + } + + restore_gdb_sanity(); + + free_all_bufs(); + + hq_close(); +} + +/* + * Check whether a SIGINT was received during the execution of a command, + * clearing the flag if it was set. This allows individual commands or + * entities to do whatever is appropriate to handle CTRL-C. + */ +int +received_SIGINT(void) +{ + if (pc->flags & _SIGINT_) { + pc->flags &= ~_SIGINT_; + pc->sigint_cnt = 0; + if (pc->ifile_in_progress) { + pc->ifile_in_progress = 0; + pc->ifile_offset = 0; + } + return TRUE; + } else + return FALSE; +} + + +/* + * Look for an executable file that begins with #! + */ +static int +is_shell_script(char *s) +{ + int fd; + char interp[2]; + struct stat sbuf; + + if ((fd = open(s, O_RDONLY)) < 0) + return FALSE; + + if (isatty(fd)) + return FALSE; + + if (read(fd, interp, 2) != 2) { + close(fd); + return FALSE; + } + + if (!STRNEQ(interp, "#!")) { + close(fd); + return FALSE; + } + + close(fd); + + if (stat(s, &sbuf) == -1) + return FALSE; + + if (!(sbuf.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))) + return FALSE; + + return TRUE; +} + +/* + * After verifying the user's input file, loop through each line, executing + * one command at a time. This command pretty much does the same as + * get_command_line(), but also kicks off the command execution as well. + * It's kept self-contained, as indicated by the RUNTIME_IFILE flag, and + * keeps its own internal sanity by calling restore_ifile_sanity() between + * each line. + */ +void +exec_input_file(void) +{ + char *file; + FILE *incoming_fp; + char buf[BUFSIZE]; + ulong this; + + /* + * Do start-up .rc or input files in the proper order. + */ + if (pc->flags & RCHOME_IFILE) { + this = RCHOME_IFILE; + pc->flags &= ~RCHOME_IFILE; + } else if (pc->flags & RCLOCAL_IFILE) { + this = RCLOCAL_IFILE; + pc->flags &= ~RCLOCAL_IFILE; + } else if (pc->flags & CMDLINE_IFILE) { + this = CMDLINE_IFILE; + pc->flags &= ~CMDLINE_IFILE; + } else + this = 0; + + if (pc->flags & RUNTIME_IFILE) { + error(INFO, "embedded input files not allowed!\n"); + return; + } + + if (argcnt < 2) { + error(INFO, "no input file entered!\n"); + return; + } else + file = args[1]; + + if (!file_exists(file, NULL)) { + error(INFO, "%s: %s\n", file, strerror(ENOENT)); + return; + } + + if (is_elf_file(file)) { + error(INFO, "input from executable files not supported yet!\n"); + return; + } + + if (is_shell_script(file)) { + error(INFO, "input from shell scripts not supported yet!\n"); + return; + } + + if ((pc->ifile = fopen(file, "r")) == NULL) { + error(INFO, "%s: %s\n", file, strerror(errno)); + return; + } + + pc->flags |= RUNTIME_IFILE; + incoming_fp = fp; + + /* + * Handle runtime commands that use input files. + */ + if ((pc->ifile_in_progress = this) == 0) { + if (!pc->runtime_ifile_cmd) { + if (!(pc->runtime_ifile_cmd = (char *)malloc(BUFSIZE))) { + error(INFO, + "cannot malloc input file command line buffer\n"); + return; + } + BZERO(pc->runtime_ifile_cmd, BUFSIZE); + } + if (!strlen(pc->runtime_ifile_cmd)) + strcpy(pc->runtime_ifile_cmd, pc->orig_line); + pc->ifile_in_progress = RUNTIME_IFILE; + } + + /* + * If there's an offset, then there was a FATAL error caused + * by the last command executed from the input file. + */ + if (pc->ifile_offset) + fseek(pc->ifile, (long)pc->ifile_offset, SEEK_SET); + + while (fgets(buf, BUFSIZE-1, pc->ifile)) { + /* + * Restore normal environment. + */ + fp = incoming_fp; + restore_ifile_sanity(); + BZERO(pc->command_line, BUFSIZE); + BZERO(pc->orig_line, BUFSIZE); + if (this & (RCHOME_IFILE|RCLOCAL_IFILE)) + pc->curcmd_flags |= FROM_RCFILE; + + pc->ifile_offset = ftell(pc->ifile); + + if (STRNEQ(buf, "#") || STREQ(buf, "\n")) + continue; + + check_special_handling(buf); + strcpy(pc->command_line, buf); + clean_line(pc->command_line); + strcpy(pc->orig_line, pc->command_line); + strip_linefeeds(pc->orig_line); + resolve_aliases(); + + switch (setup_redirect(FROM_INPUT_FILE)) + { + case REDIRECT_NOT_DONE: + case REDIRECT_TO_PIPE: + case REDIRECT_TO_FILE: + break; + + case REDIRECT_SHELL_ESCAPE: + case REDIRECT_SHELL_COMMAND: + continue; + + case REDIRECT_FAILURE: + goto done_input; + } + + if (CRASHDEBUG(1)) + console(buf); + + if (!(argcnt = parse_line(pc->command_line, args))) + continue; + + if (!(pc->flags & SILENT)) { + fprintf(fp, "%s%s", pc->prompt, buf); + fflush(fp); + } + + exec_command(); + } + +done_input: + + fclose(pc->ifile); + pc->ifile = NULL; + pc->flags &= ~RUNTIME_IFILE; + pc->ifile_offset = 0; + if (pc->runtime_ifile_cmd) + BZERO(pc->runtime_ifile_cmd, BUFSIZE); + pc->ifile_in_progress = 0; +} + +/* + * Prime the alias list with a few built-in's. + */ +void +alias_init(char *inbuf) +{ + char buf[BUFSIZE]; + + if (inbuf) { + strcpy(buf, inbuf); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + return; + } + + strcpy(buf, "alias man help"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias ? help"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias quit q"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias sf set scroll off"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias sn set scroll on"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias hex set radix 16"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias dec set radix 10"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias g gdb"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias px p -x"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias pd p -d"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias for foreach"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias size *"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias dmesg log"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); + + strcpy(buf, "alias lsmod mod"); + argcnt = parse_line(buf, args); + allocate_alias(ALIAS_BUILTIN); +} + +/* + * Before the command line is parsed, take a snapshot and parse the snapshot. + * If args[0] is an known alias, recreate the pc->command_line string with + * the alias substitution. + */ +static void +resolve_aliases(void) +{ + int i; + struct alias_data *ad; + int found; + char *p1, *remainder; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + + if (!strlen(pc->command_line)) + return; + + strcpy(buf1, pc->command_line); + argcnt = parse_line(buf1, args); + + if (argcnt > 1) { + strcpy(buf2, &pc->command_line[args[1] - buf1]); + remainder = buf2; + } else + remainder = NULL; + + found = FALSE; + for (ad = alias_head.next; ad; ad = ad->next) { + if (STREQ(ad->alias, args[0])) { + for (i = 0; i < ad->argcnt; i++) + args[i] = ad->args[i]; + found = TRUE; + break; + } + } + + if (!found) + return; + + BZERO(pc->command_line, BUFSIZE); + p1 = pc->command_line; + + for (i = 0; i < ad->argcnt; i++) { + snprintf(p1, BUFSIZE - (p1-pc->command_line), "%s ", args[i]); + while (*p1) + p1++; + if ((p1 - pc->command_line) >= BUFSIZE) + break; + } + if (remainder) { + if ((strlen(remainder)+strlen(pc->command_line)) < BUFSIZE) + strcat(pc->command_line, remainder); + else + error(INFO, "command line overflow.\n"); + } else if (strlen(pc->command_line) >= (BUFSIZE-1)) + error(INFO, "command line overflow.\n"); + + clean_line(pc->command_line); +} + +/* + * If input string is an alias, return a pointer to the alias_data struct. + */ +struct alias_data * +is_alias(char *s) +{ + struct alias_data *ad; + + for (ad = alias_head.next; ad; ad = ad->next) { + if (STREQ(ad->alias, s)) + return(ad); + } + return NULL; +} + +/* + * .rc file commands that are "set" commands may be performed prior + * to initialization, so pass them to cmd_set() for consideration. + * All other commands are flagged for execution by exec_input_file() + * after session initialization is complete. + */ +void +resolve_rc_cmd(char *s, int origin) +{ + clean_line(s); + + if (*s == '#') + return; + + if ((argcnt = parse_line(s, args)) == 0) + return; + + if (STREQ(args[0], "set")) { + optind = 0; + cmd_set(); + } + + switch (origin) + { + case ALIAS_RCHOME: + pc->flags |= RCHOME_IFILE; + break; + case ALIAS_RCLOCAL: + pc->flags |= RCLOCAL_IFILE; + break; + } + + return; +} + + +/* + * The "alias" command. With no arguments, list all aliases. With one + * argument -- which must be an alias -- display the string it's aliased to. + * With two or more arguments, setup a new alias, where the first argument + * is the alias, and the remaining arguments make up the alias string. + * If the second arg is the NULL string "", delete the alias. + */ +void +cmd_alias(void) +{ + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + switch (argcnt) + { + case 1: + list_aliases(NULL); + break; + + case 2: + list_aliases(args[1]); + break; + + default: + if (allocate_alias(ALIAS_RUNTIME)) + list_aliases(args[1]); + break; + } +} + +/* + * Dump the current set of aliases. + */ +static void +list_aliases(char *s) +{ + int i; + struct alias_data *ad; + int found, precision; + char buf[BUFSIZE]; + + if (!alias_head.next) { + error(INFO, "alias list is empty\n"); + return; + } + + BZERO(buf, BUFSIZE); + found = FALSE; + precision = 7; + + for (ad = alias_head.next; ad; ad = ad->next) { + switch (ad->origin) + { + case ALIAS_RCLOCAL: + sprintf(buf, ".%src", pc->program_name); + if (strlen(buf) > precision) + precision = strlen(buf); + break; + case ALIAS_RCHOME: + sprintf(buf, "$HOME/.%src", pc->program_name); + if (strlen(buf) > precision) + precision = strlen(buf); + break; + } + } + + fprintf(fp, "ORIGIN"); + pad_line(fp, precision-6, ' '); + + BZERO(buf, BUFSIZE); + fprintf(fp, " ALIAS COMMAND\n"); + + for (ad = alias_head.next; ad; ad = ad->next) { + if (s && !STREQ(s, ad->alias)) + continue; + + found = TRUE; + + switch (ad->origin) + { + case ALIAS_RUNTIME: + sprintf(buf, "runtime"); + break; + case ALIAS_RCLOCAL: + sprintf(buf, ".%src", pc->program_name); + break; + case ALIAS_RCHOME: + sprintf(buf, "$HOME/.%src", pc->program_name); + break; + case ALIAS_BUILTIN: + sprintf(buf, "builtin"); + break; + } + + fprintf(fp, "%s ", buf); + pad_line(fp, precision-strlen(buf), ' '); + + fprintf(fp, "%-7s ", ad->alias); + + for (i = 0; i < ad->argcnt; i++) { + fprintf(fp, "%s ", ad->args[i]); + } + fprintf(fp, "\n"); + } + + if (s && !found) + fprintf(fp, "alias does not exist: %s\n", s); + +} + +/* + * Verify the alias request set up in the args[] array: + * + * 1. make sure that the alias string starts with a legitimate command. + * 2. if the already exists, deallocate its current version. + * + * Then malloc space for the alias string, and link it in to the alias list. + */ +static int +allocate_alias(int origin) +{ + int i; + int size; + struct alias_data *ad; + struct alias_data *newad; + char *p1, *enclosed_string; + int found; + + if ((enclosed_string = strstr(args[2], " "))) + *enclosed_string = NULLCHAR; + + found = FALSE; + + if (get_command_table_entry(args[1])) { + error(INFO, "cannot alias existing command name: %s\n", + args[1]); + return FALSE; + } + + if (get_command_table_entry(args[2])) + found = TRUE; + + if (!found) { + if (!strlen(args[2])) { + if (alias_exists(args[1])) { + deallocate_alias(args[1]); + fprintf(fp, "alias deleted: %s\n", args[1]); + } + } else { + error(INFO, + "invalid alias attempt on non-existent command: %s\n", + args[2]); + } + return FALSE; + } + + if (alias_exists(args[1])) + deallocate_alias(args[1]); + + if (enclosed_string) + *enclosed_string = ' '; + + size = sizeof(struct alias_data) + argcnt; + for (i = 0; i < argcnt; i++) + size += strlen(args[i]); + + if ((newad = (struct alias_data *)malloc(size+1)) == NULL) { + error(INFO, "alias_data malloc: %s\n", strerror(errno)); + return FALSE; + } + + BZERO(newad, size); + newad->next = NULL; + newad->size = size; + newad->origin = origin; + + p1 = newad->argbuf; + for (i = 1; i < argcnt; i++) { + sprintf(p1, "%s ", args[i]); + while (*p1) + p1++; + } + p1 = strstr(newad->argbuf, " "); + *p1 = NULLCHAR; + + newad->alias = newad->argbuf; + newad->argcnt = parse_line(p1+1, newad->args); + + for (ad = &alias_head; ad->next; ad = ad->next) + ; + ad->next = newad; + + return TRUE; +} + + +/* + * Check whether the passed-in string is a currently-existing alias. + */ +static int +alias_exists(char *s) +{ + struct alias_data *ad; + + if (!alias_head.next) + return FALSE; + + for (ad = alias_head.next; ad; ad = ad->next) + if (STREQ(ad->alias, s)) + return TRUE; + + return FALSE; +} + +/* + * If the passed-in string is an alias, delink it and free its memory. + */ +void +deallocate_alias(char *s) +{ + struct alias_data *ad, *lastad; + + for (ad = alias_head.next, lastad = &alias_head; ad; ad = ad->next) { + if (!STREQ(ad->alias, s)) { + lastad = ad; + continue; + } + + lastad->next = ad->next; + free(ad); + break; + } +} + +/* + * "help -a" output + */ +void +dump_alias_data(void) +{ + int i; + struct alias_data *ad; + + fprintf(fp, "alias_head.next: %lx\n\n", (ulong)alias_head.next); + + for (ad = alias_head.next; ad; ad = ad->next) { + fprintf(fp, " next: %lx\n", (ulong)ad->next); + fprintf(fp, " alias: %s\n", ad->alias); + fprintf(fp, " size: %d\n", ad->size); + fprintf(fp, " origin: "); + switch (ad->origin) + { + case ALIAS_RUNTIME: + fprintf(fp, "runtime setting \n"); + break; + case ALIAS_RCLOCAL: + fprintf(fp, ".%src \n", pc->program_name); + break; + case ALIAS_RCHOME: + fprintf(fp, "$HOME/.%src \n", pc->program_name); + break; + case ALIAS_BUILTIN: + fprintf(fp, "builtin\n"); + break; + } + fprintf(fp, " argcnt: %d\n", ad->argcnt); + for (i = 0; i < ad->argcnt; i++) + fprintf(fp, " args[%d]: %lx: %s\n", + i, (ulong)ad->args[i], ad->args[i]); + fprintf(fp, "\n"); + } +} + + +/* + * Repeat a command on a live system. + */ +void +cmd_repeat(void) +{ + ulong delay; + char buf[BUFSIZE]; + char bufsave[BUFSIZE]; + FILE *incoming_fp; + + if (argcnt == 1) + cmd_usage(pc->curcmd, SYNOPSIS); + + delay = 0; + + if (args[1][0] == '-') { + switch (args[1][1]) + { + default: + case NULLCHAR: + cmd_usage(pc->curcmd, SYNOPSIS); + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '0': + delay = dtol(&args[1][1], FAULT_ON_ERROR, NULL); + concat_args(buf, 2, FALSE); + break; + } + } else + concat_args(buf, 1, FALSE); + + check_special_handling(buf); + + strcpy(pc->command_line, buf); + resolve_aliases(); + if (!argcnt) + return; + strcpy(buf, pc->command_line); + + strcpy(bufsave, buf); + argcnt = parse_line(buf, args); + if (!argcnt) + return; + + if (STREQ(args[0], "<") && (pc->flags & TTY) && + (pc->flags & SCROLL) && pc->scroll_command) + error(FATAL, + "scrolling must be turned off when repeating an input file\n"); + + pc->curcmd_flags |= REPEAT; + incoming_fp = fp; + + while (TRUE) { + optind = 0; + fp = incoming_fp; + exec_command(); + free_all_bufs(); + wait_for_children(ZOMBIES_ONLY); + + if (received_SIGINT() || !output_open()) + break; + + if ((pc->flags & TTY) && !is_a_tty("/dev/tty")) + break; + + if (!(pc->curcmd_flags & REPEAT)) + break; + + if (delay) + sleep(delay); + + strcpy(buf, bufsave); + argcnt = parse_line(buf, args); + } +} + +/* + * Initialize readline, set the editing mode, and then perform any + * crash-specific bindings, etc. + */ +static void +readline_init(void) +{ + rl_initialize(); + + if (STREQ(pc->editing_mode, "vi")) { + rl_editing_mode = vi_mode; + + rl_bind_key(CTRL('N'), rl_get_next_history); + rl_bind_key(CTRL('P'), rl_get_previous_history); + + rl_bind_key_in_map(CTRL('P'), rl_get_previous_history, + vi_insertion_keymap); + rl_bind_key_in_map(CTRL('N'), rl_get_next_history, + vi_insertion_keymap); + + rl_generic_bind(ISFUNC, "[A", (char *)rl_get_previous_history, + vi_movement_keymap); + rl_generic_bind(ISFUNC, "[B", (char *)rl_get_next_history, + vi_movement_keymap); + } + + if (STREQ(pc->editing_mode, "emacs")) { + rl_editing_mode = emacs_mode; + } +} + +/* + * Find and set the tty string of this session as seen in "ps -ef" output. + */ +static void +set_my_tty(void) +{ + char buf[BUFSIZE]; + char *arglist[MAXARGS]; + int argc; + FILE *pipe; + + strcpy(pc->my_tty, "?"); + + if (file_exists("/usr/bin/tty", NULL)) { + sprintf(buf, "/usr/bin/tty"); + if ((pipe = popen(buf, "r")) == NULL) + return; + + while (fgets(buf, BUFSIZE, pipe)) { + if (STRNEQ(buf, "/dev/")) { + strcpy(pc->my_tty, strip_line_end(&buf[strlen("/dev/")])); + break; + } + } + pclose(pipe); + return; + } + + sprintf(buf, "ps -ef | grep ' %d '", getpid()); + + if (CRASHDEBUG(1)) + fprintf(fp, "popen(%s)\n", buf); + + if ((pipe = popen(buf, "r")) == NULL) + return; + + while (fgets(buf, BUFSIZE, pipe)) { + argc = parse_line(buf, arglist); + if ((argc >= 8) && (atoi(arglist[1]) == getpid())) { + if (strlen(arglist[5]) < 9) + strcpy(pc->my_tty, arglist[5]); + else + strncpy(pc->my_tty, arglist[5], 9); + } + } + pclose(pipe); +} + +/* + * Check whether SIGINT's are allowed before shipping a request off to gdb. + */ +int +interruptible(void) +{ + if (!(pc->flags & RUNTIME)) + return FALSE; + + if (!(pc->flags & TTY)) + return FALSE; + + if ((pc->redirect & (FROM_INPUT_FILE|REDIRECT_NOT_DONE)) == + (FROM_INPUT_FILE|REDIRECT_NOT_DONE)) + return TRUE; + + if (strlen(pc->pipe_command)) + return FALSE; + + return TRUE; +} + + +/* + * Set up the standard output pipe using whichever was selected during init. + */ + +static int +setup_stdpipe(void) +{ + char *path; + + if (pipe(pc->pipefd) < 0) { + error(INFO, "pipe system call failed: %s", strerror(errno)); + return FALSE; + } + + if ((pc->stdpipe_pid = fork()) < 0) { + error(INFO, "fork system call failed: %s", strerror(errno)); + return FALSE; + } + + path = NULL; + + if (pc->stdpipe_pid > 0) { + pc->redirect |= REDIRECT_PID_KNOWN; + + close(pc->pipefd[0]); /* parent closes read end */ + + if ((pc->stdpipe = fdopen(pc->pipefd[1], "w")) == NULL) { + error(INFO, "fdopen system call failed: %s", + strerror(errno)); + return FALSE; + } + setbuf(pc->stdpipe, NULL); + + switch (pc->scroll_command) + { + case SCROLL_LESS: + strcpy(pc->pipe_command, less_argv[0]); + break; + case SCROLL_MORE: + strcpy(pc->pipe_command, more_argv[0]); + break; + case SCROLL_CRASHPAGER: + strcpy(pc->pipe_command, CRASHPAGER_argv[0]); + break; + } + + if (CRASHDEBUG(2)) + console("pipe: %lx\n", pc->stdpipe); + return TRUE;; + + } else { + close(pc->pipefd[1]); /* child closes write end */ + + if (dup2(pc->pipefd[0], 0) != 0) { + perror("child dup2 failed"); + clean_exit(1); + } + + if (CRASHDEBUG(2)) + console("execv: %d\n", getpid()); + + switch (pc->scroll_command) + { + case SCROLL_LESS: + path = less_argv[0]; + execv(path, less_argv); + break; + + case SCROLL_MORE: + path = more_argv[0]; + execv(path, more_argv); + break; + + case SCROLL_CRASHPAGER: + path = CRASHPAGER_argv[0]; + execv(path, CRASHPAGER_argv); + break; + } + + perror(path); + fprintf(stderr, "execv of scroll command failed\n"); + exit(1); + } +} + +static void +wait_for_children(ulong waitflag) +{ + int status, pid; + + while (TRUE) { + switch (pid = waitpid(-1, &status, WNOHANG)) + { + case 0: + if (CRASHDEBUG(2)) + console("wait_for_children: child running...\n"); + if (waitflag == ZOMBIES_ONLY) + return; + break; + + case -1: + if (CRASHDEBUG(2)) + console("wait_for_children: no children alive\n"); + return; + + default: + console("wait_for_children(%d): reaped %d\n", + waitflag, pid); + if (CRASHDEBUG(2)) + fprintf(fp, "wait_for_children: reaped %d\n", pid); + break; + } + stall(1000); + } +} + +/* + * Run an escaped shell command, redirecting the output to + * the current output file. + */ +int +shell_command(char *cmd) +{ + FILE *pipe; + char buf[BUFSIZE]; + + if ((pipe = popen(cmd, "r")) == NULL) { + error(INFO, "cannot open pipe: %s\n", cmd); + pc->redirect &= ~REDIRECT_SHELL_COMMAND; + pc->redirect |= REDIRECT_FAILURE; + return REDIRECT_FAILURE; + } + + while (fgets(buf, BUFSIZE, pipe)) + fputs(buf, fp); + pclose(pipe); + + return REDIRECT_SHELL_COMMAND; +} + +static int +verify_args_input_file(char *fileptr) +{ + struct stat stat; + + if (!file_exists(fileptr, &stat)) { + if (CRASHDEBUG(1)) + error(INFO, "%s: no such file\n", fileptr); + } else if (!S_ISREG(stat.st_mode)) { + if (CRASHDEBUG(1)) + error(INFO, "%s: not a regular file\n", fileptr); + } else if (!stat.st_size) { + if (CRASHDEBUG(1)) + error(INFO, "%s: file is empty\n", fileptr); + } else if (!file_readable(fileptr)) { + if (CRASHDEBUG(1)) + error(INFO, "%s: permission denied\n", fileptr); + } else + return TRUE; + + return FALSE; +} + +/* + * Verify a command line argument input file. + */ + +#define NON_FILENAME_CHARS "*?!|\'\"{}<>;,^()$~" + +int +is_args_input_file(struct command_table_entry *ct, struct args_input_file *aif) +{ + int c, start, whites, args_used; + char *p1, *p2, *curptr, *fileptr; + char buf[BUFSIZE]; + int retval; + + if (pc->curcmd_flags & NO_MODIFY) + return FALSE; + + BZERO(aif, sizeof(struct args_input_file)); + retval = FALSE; + + if (STREQ(ct->name, "gdb")) { + curptr = pc->orig_line; +next_gdb: + if ((p1 = strstr(curptr, "<"))) { + while (STRNEQ(p1, "<<")) { + p2 = p1+2; + if (!(p1 = strstr(p2, "<"))) + return retval; + } + } + + if (!p1) + return retval; + + start = p1 - curptr; + p2 = p1+1; + + for (whites = 0; whitespace(*p2); whites++) + p2++; + + if (*p2 == NULLCHAR) + return retval; + + strcpy(buf, p2); + p2 = buf; + + if (*p2) { + fileptr = p2; + while (*p2 && !whitespace(*p2) && + (strpbrk(p2, NON_FILENAME_CHARS) != p2)) + p2++; + *p2 = NULLCHAR; + if (verify_args_input_file(fileptr)) { + if (retval == TRUE) { + error(INFO, + "ignoring multiple argument input files: " + "%s and %s\n", + aif->fileptr, fileptr); + return FALSE; + } + aif->start = start; + aif->resume = start + (p2-buf) + whites + 1; + aif->fileptr = GETBUF(strlen(fileptr)+1); + strcpy(aif->fileptr, fileptr); + aif->is_gdb_cmd = TRUE; + retval = TRUE; + } + } + + curptr = p1+1; + goto next_gdb; + } + + for (c = 0; c < argcnt; c++) { + if (STRNEQ(args[c], "<") && !STRNEQ(args[c], "<<")) { + if (strlen(args[c]) > 1) { + fileptr = &args[c][1]; + args_used = 1; + } else { + if ((c+1) == argcnt) + error(FATAL, + "< requires a file argument\n"); + fileptr = args[c+1]; + args_used = 2; + } + + if (!verify_args_input_file(fileptr)) + continue; + + if (retval == TRUE) + error(FATAL, + "multiple input files are not supported\n"); + + aif->index = c; + aif->fileptr = GETBUF(strlen(fileptr)+1); + strcpy(aif->fileptr, fileptr); + aif->args_used = args_used; + retval = TRUE; + continue; + } + + if (STRNEQ(args[c], "(")) { + curptr = args[c]; +next_expr: + if ((p1 = strstr(curptr, "<"))) { + while (STRNEQ(p1, "<<")) { + p2 = p1+2; + if (!(p1 = strstr(p2, "<"))) + continue; + } + } + + if (!p1) + continue; + + start = p1 - curptr; + p2 = p1+1; + + for (whites = 0; whitespace(*p2); whites++) + p2++; + + if (*p2 == NULLCHAR) + continue; + + strcpy(buf, p2); + p2 = buf; + + if (*p2) { + fileptr = p2; + while (*p2 && !whitespace(*p2) && + (strpbrk(p2, NON_FILENAME_CHARS) != p2)) + p2++; + *p2 = NULLCHAR; + + if (!verify_args_input_file(fileptr)) + continue; + + if (retval == TRUE) { + error(INFO, + "ignoring multiple argument input files: " + "%s and %s\n", + aif->fileptr, fileptr); + return FALSE; + } + + retval = TRUE; + + aif->in_expression = TRUE; + aif->args_used = 1; + aif->index = c; + aif->start = start; + aif->resume = start + (p2-buf) + whites + 1; + aif->fileptr = GETBUF(strlen(fileptr)+1); + strcpy(aif->fileptr, fileptr); + } + + curptr = p1+1; + goto next_expr; + } + } + + return retval; +} + +static void +modify_orig_line(char *inbuf, struct args_input_file *aif) +{ + char buf[BUFSIZE]; + + strcpy(buf, pc->orig_line); + strcpy(&buf[aif->start], inbuf); + strcat(buf, &pc->orig_line[aif->resume]); + strcpy(pc->orig_line, buf); +} + +static void +modify_expression_arg(char *inbuf, char **aif_args, struct args_input_file *aif) +{ + char *old, *new; + + old = aif_args[aif->index]; + new = GETBUF(strlen(aif_args[aif->index]) + strlen(inbuf)); + + strcpy(new, old); + strcpy(&new[aif->start], inbuf); + strcat(new, &old[aif->resume]); + + aif_args[aif->index] = new; +} + +/* + * Sequence through an args input file, and for each line, + * reinitialize the global args[] and argcnt, and issue the command. + */ +void +exec_args_input_file(struct command_table_entry *ct, struct args_input_file *aif) +{ + char buf[BUFSIZE]; + int i, c, aif_cnt; + int orig_argcnt; + char *aif_args[MAXARGS]; + char *new_args[MAXARGS]; + char *orig_args[MAXARGS]; + char orig_line[BUFSIZE]; + + if ((pc->args_ifile = fopen(aif->fileptr, "r")) == NULL) + error(FATAL, "%s: %s\n", aif->fileptr, strerror(errno)); + + if (aif->is_gdb_cmd) + strcpy(orig_line, pc->orig_line); + + BCOPY(args, orig_args, sizeof(args)); + orig_argcnt = argcnt; + + while (fgets(buf, BUFSIZE-1, pc->args_ifile)) { + clean_line(buf); + if ((strlen(buf) == 0) || (buf[0] == '#')) + continue; + + if (aif->is_gdb_cmd) { + console("(gdb) before: [%s]\n", orig_line); + strcpy(pc->orig_line, orig_line); + modify_orig_line(buf, aif); + console("(gdb) after: [%s]\n", pc->orig_line); + } else if (aif->in_expression) { + console("expr before: [%s]\n", orig_args[aif->index]); + BCOPY(orig_args, aif_args, sizeof(aif_args)); + modify_expression_arg(buf, aif_args, aif); + BCOPY(aif_args, args, sizeof(aif_args)); + console("expr after: [%s]\n", args[aif->index]); + } else { + if (!(aif_cnt = parse_line(buf, aif_args))) + continue; + + for (i = 0; i < orig_argcnt; i++) + console("%s[%d]:%s %s", + (i == 0) ? "before: " : "", + i, orig_args[i], + (i+1) == orig_argcnt ? "\n" : ""); + + for (i = 0; i < aif->index; i++) + new_args[i] = orig_args[i]; + for (i = aif->index, c = 0; c < aif_cnt; c++, i++) + new_args[i] = aif_args[c]; + for (i = aif->index + aif_cnt, + c = aif->index + aif->args_used; + c < orig_argcnt; c++, i++) + new_args[i] = orig_args[c]; + + argcnt = orig_argcnt - aif->args_used + aif_cnt; + new_args[argcnt] = NULL; + BCOPY(new_args, args, sizeof(args)); + + for (i = 0; i < argcnt; i++) + console("%s[%d]:%s %s", + (i == 0) ? " after: " : "", + i, args[i], + (i+1) == argcnt ? "\n" : ""); + } + + optind = argerrs = 0; + pc->cmdgencur++; + + if (setjmp(pc->foreach_loop_env)) + pc->flags &= ~IN_FOREACH; + else { + pc->flags |= IN_FOREACH; + (*ct->func)(); + pc->flags &= ~IN_FOREACH; + } + + if (pc->cmd_cleanup) + pc->cmd_cleanup(pc->cmd_cleanup_arg); + + free_all_bufs(); + } + + fclose(pc->args_ifile); + pc->args_ifile = NULL; +} diff --git a/configure.c b/configure.c new file mode 100644 index 00000000..77ac81d9 --- /dev/null +++ b/configure.c @@ -0,0 +1,1686 @@ +/* configure.c - core analysis suite + * + * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2013 David Anderson + * Copyright (C) 2002-2013 Red Hat, Inc. 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. + */ + +/* + * define, clear and undef dynamically update the top-level Makefile: + * + * -b define: TARGET, GDB, GDB_FILES, GDB_OFILES, GDB_PATCH_FILES, + * TARGET_CFLAGS, LDFLAGS, GDB_CONF_FLAGS and GPL_FILES + * create: build_data.c + * + * -d define: TARGET, GDB, GDB_FILES, GDB_OFILES, GDB_PATCH_FILES, + * TARGET_CFLAGS, LDFLAGS, GDB_CONF_FLAGS and PROGRAM (for daemon) + * create: build_data.c + * + * -u clear: TARGET, GDB, GDB_FILES, GDB_OFILES, VERSION, GDB_PATCH_FILES, + * TARGET_CFLAGS, LDFLAGS, GDB_CONF_FLAGS and GPL_FILES + * undef: WARNING_ERROR, WARNING_OPTIONS + * + * -r define: GDB_FILES, VERSION, GDB_PATCH_FILES GPL_FILES + * + * -w define: WARNING_OPTIONS + * undef: WARNING_ERROR + * + * -W define: WARNING_ERROR, WARNING_OPTIONS + * + * -n undef: WARNING_ERROR, WARNING_OPTIONS + * + * -g define: GDB + * + * -p Create or remove .rh_rpm_package file + * + * -q Don't print configuration + * + * -s Create crash.spec file + * + * -x Add extra libraries/flags to build + */ + +#include +#include +#include +#include +#include +#include + +struct supported_gdb_version; +void build_configure(struct supported_gdb_version *); +void release_configure(char *, struct supported_gdb_version *); +void make_rh_rpm_package(char *, int); +void unconfigure(void); +void set_warnings(int); +void show_configuration(void); +void target_rebuild_instructions(struct supported_gdb_version *, char *); +void arch_mismatch(struct supported_gdb_version *); +void get_current_configuration(struct supported_gdb_version *); +void makefile_setup(FILE **, FILE **); +void makefile_create(FILE **, FILE **); +char *strip_linefeeds(char *); +char *upper_case(char *, char *); +char *lower_case(char *, char *); +char *shift_string_left(char *, int); +char *shift_string_right(char *, int); +char *strip_beginning_whitespace(char *); +char *strip_ending_whitespace(char *); +char *strip_linefeeds(char *); +int file_exists(char *); +int count_chars(char *, char); +void make_build_data(char *); +void gdb_configure(struct supported_gdb_version *); +int parse_line(char *, char **); +struct supported_gdb_version *setup_gdb_defaults(void); +struct supported_gdb_version *store_gdb_defaults(struct supported_gdb_version *); +void make_spec_file(struct supported_gdb_version *); +void set_initial_target(struct supported_gdb_version *); +char *target_to_name(int); +int name_to_target(char *); +char *get_extra_flags(char *, char *); +void add_extra_lib(char *); + +#define TRUE 1 +#define FALSE 0 + +#undef X86 +#undef ALPHA +#undef PPC +#undef IA64 +#undef S390 +#undef S390X +#undef PPC64 +#undef X86_64 +#undef ARM +#undef ARM64 + +#define UNKNOWN 0 +#define X86 1 +#define ALPHA 2 +#define PPC 3 +#define IA64 4 +#define S390 5 +#define S390X 6 +#define PPC64 7 +#define X86_64 8 +#define ARM 9 +#define ARM64 10 + +#define TARGET_X86 "TARGET=X86" +#define TARGET_ALPHA "TARGET=ALPHA" +#define TARGET_PPC "TARGET=PPC" +#define TARGET_IA64 "TARGET=IA64" +#define TARGET_S390 "TARGET=S390" +#define TARGET_S390X "TARGET=S390X" +#define TARGET_PPC64 "TARGET=PPC64" +#define TARGET_X86_64 "TARGET=X86_64" +#define TARGET_ARM "TARGET=ARM" +#define TARGET_ARM64 "TARGET=ARM64" + +#define TARGET_CFLAGS_X86 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" +#define TARGET_CFLAGS_ALPHA "TARGET_CFLAGS=" +#define TARGET_CFLAGS_PPC "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" +#define TARGET_CFLAGS_IA64 "TARGET_CFLAGS=" +#define TARGET_CFLAGS_S390 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" +#define TARGET_CFLAGS_S390X "TARGET_CFLAGS=" +#define TARGET_CFLAGS_PPC64 "TARGET_CFLAGS=-m64" +#define TARGET_CFLAGS_X86_64 "TARGET_CFLAGS=" +#define TARGET_CFLAGS_ARM "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" +#define TARGET_CFLAGS_ARM_ON_X86 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64" +#define TARGET_CFLAGS_ARM_ON_X86_64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64" +#define TARGET_CFLAGS_X86_ON_X86_64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64" +#define TARGET_CFLAGS_PPC_ON_PPC64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64 -fPIC" +#define TARGET_CFLAGS_ARM64 "TARGET_CFLAGS=" +#define TARGET_CFLAGS_ARM64_ON_X86_64 "TARGET_CFLAGS=" + +#define GDB_TARGET_DEFAULT "GDB_CONF_FLAGS=" +#define GDB_TARGET_ARM_ON_X86 "GDB_CONF_FLAGS=--target=arm-elf-linux" +#define GDB_TARGET_ARM_ON_X86_64 "GDB_CONF_FLAGS=--target=arm-elf-linux CFLAGS=-m32" +#define GDB_TARGET_X86_ON_X86_64 "GDB_CONF_FLAGS=--target=i686-pc-linux-gnu CFLAGS=-m32" +#define GDB_TARGET_PPC_ON_PPC64 "GDB_CONF_FLAGS=--target=ppc-elf-linux CFLAGS=-m32" +#define GDB_TARGET_ARM64_ON_X86_64 "GDB_CONF_FLAGS=--target=aarch64-elf-linux" /* TBD */ + +/* + * The original plan was to allow the use of a particular version + * of gdb for a given architecture. But for practical purposes, + * it's a one-size-fits-all scheme, and they all use the default + * unless overridden. + */ + +#define GDB_5_3 (0) +#define GDB_6_0 (1) +#define GDB_6_1 (2) +#define GDB_7_0 (3) +#define GDB_7_3_1 (4) +#define GDB_7_6 (5) +#define SUPPORTED_GDB_VERSIONS (GDB_7_6 + 1) + +int default_gdb = GDB_7_6; + +struct supported_gdb_version { + char *GDB; + char *GDB_VERSION_IN; + char *GDB_FILES; + char *GDB_OFILES; + char *GDB_PATCH_FILES; + char *GDB_FLAGS; + char *GPL; +} supported_gdb_versions[SUPPORTED_GDB_VERSIONS] = { + { + "GDB=gdb-5.3post-0.20021129.36rh", + "Red Hat Linux (5.3post-0.20021129.36rh)", + "GDB_FILES=${GDB_5.3post-0.20021129.36rh_FILES}", + "GDB_OFILES=${GDB_5.3post-0.20021129.36rh_OFILES}", + "GDB_PATCH_FILES=", + "GDB_FLAGS=-DGDB_5_3", + "GPLv2" + }, + { + "GDB=gdb-6.0", + "6.0", + "GDB_FILES=${GDB_6.0_FILES}", + "GDB_OFILES=${GDB_6.0_OFILES}", + "GDB_PATCH_FILES=", + "GDB_FLAGS=-DGDB_6_0", + "GPLv2" + }, + { + "GDB=gdb-6.1", + "6.1", + "GDB_FILES=${GDB_6.1_FILES}", + "GDB_OFILES=${GDB_6.1_OFILES}", + "GDB_PATCH_FILES=gdb-6.1.patch", + "GDB_FLAGS=-DGDB_6_1", + "GPLv2" + }, + { + "GDB=gdb-7.0", + "7.0", + "GDB_FILES=${GDB_7.0_FILES}", + "GDB_OFILES=${GDB_7.0_OFILES}", + "GDB_PATCH_FILES=gdb-7.0.patch", + "GDB_FLAGS=-DGDB_7_0", + "GPLv3" + }, + { + "GDB=gdb-7.3.1", + "7.3.1", + "GDB_FILES=${GDB_7.3.1_FILES}", + "GDB_OFILES=${GDB_7.3.1_OFILES}", + "GDB_PATCH_FILES=gdb-7.3.1.patch", + "GDB_FLAGS=-DGDB_7_3_1", + "GPLv3" + }, + { + "GDB=gdb-7.6", + "7.6", + "GDB_FILES=${GDB_7.6_FILES}", + "GDB_OFILES=${GDB_7.6_OFILES}", + "GDB_PATCH_FILES=gdb-7.6.patch", + "GDB_FLAGS=-DGDB_7_6", + "GPLv3" + }, +}; + +#define DAEMON 0x1 +#define QUIET 0x2 + +#define MAXSTRLEN 256 +#define MIN(a,b) (((a)<(b))?(a):(b)) + +struct target_data { + int target; + int host; + int initial_gdb_target; + int flags; + char program[MAXSTRLEN]; + char gdb_version[MAXSTRLEN]; + char release[MAXSTRLEN]; + struct stat statbuf; + const char *target_as_param; +} target_data = { 0 }; + +int +main(int argc, char **argv) +{ + int c; + struct supported_gdb_version *sp; + + sp = setup_gdb_defaults(); + + while ((c = getopt(argc, argv, "gsqnWwubdr:p:P:t:x:")) > 0) { + switch (c) { + case 'q': + target_data.flags |= QUIET; + break; + case 'u': + unconfigure(); + break; + case 'd': + target_data.flags |= DAEMON; + case 'b': + build_configure(sp); + break; + case 'r': + release_configure(optarg, sp); + break; + case 'p': + make_rh_rpm_package(optarg, 0); + break; + case 'P': + make_rh_rpm_package(optarg, 1); + break; + case 'W': + case 'w': + case 'n': + set_warnings(c); + break; + case 's': + make_spec_file(sp); + break; + case 'g': + gdb_configure(sp); + break; + case 't': + target_data.target_as_param = optarg; + break; + case 'x': + add_extra_lib(optarg); + break; + } + } + + exit(0); +} + +void +target_rebuild_instructions(struct supported_gdb_version *sp, char *target) +{ + fprintf(stderr, + "\nIn order to build a crash binary for the %s architecture:\n", + target); + + fprintf(stderr, " 1. remove the %s subdirectory\n", + &sp->GDB[strlen("GDB=")]); + fprintf(stderr, " 2. perform a \"make clean\"\n"); + fprintf(stderr, " 3. retry the build\n\n"); +} + +void +arch_mismatch(struct supported_gdb_version *sp) +{ + fprintf(stderr, + "\nThe initial build in this source tree was for the %s architecture.\n", + target_to_name(target_data.initial_gdb_target)); + + target_rebuild_instructions(sp, target_to_name(target_data.target)); + + exit(1); +} + +void +get_current_configuration(struct supported_gdb_version *sp) +{ + FILE *fp; + static char buf[512]; + char *p; + +#ifdef __alpha__ + target_data.target = ALPHA; +#endif +#ifdef __i386__ + target_data.target = X86; +#endif +#ifdef __powerpc__ + target_data.target = PPC; +#endif +#ifdef __ia64__ + target_data.target = IA64; +#endif +#ifdef __s390__ + target_data.target = S390; +#endif +#ifdef __s390x__ + target_data.target = S390X; +#endif +#ifdef __powerpc64__ + target_data.target = PPC64; +#endif +#ifdef __x86_64__ + target_data.target = X86_64; +#endif +#ifdef __arm__ + target_data.target = ARM; +#endif +#ifdef __aarch64__ + target_data.target = ARM64; +#endif + + set_initial_target(sp); + + /* + * Override target if specified on command line. + */ + target_data.host = target_data.target; + + if (target_data.target_as_param) { + if ((target_data.target == X86 || target_data.target == X86_64) && + (name_to_target((char *)target_data.target_as_param) == ARM)) { + /* + * Debugging of ARM core files supported on X86, and on + * X86_64 when built as a 32-bit executable. + */ + target_data.target = ARM; + } else if ((target_data.target == X86_64) && + (name_to_target((char *)target_data.target_as_param) == X86)) { + /* + * Build an X86 crash binary on an X86_64 host. + */ + target_data.target = X86; + } else if ((target_data.target == X86_64) && + (name_to_target((char *)target_data.target_as_param) == ARM64)) { + /* + * Build an ARM64 crash binary on an X86_64 host. + */ + target_data.target = ARM64; + } else if ((target_data.target == PPC64) && + (name_to_target((char *)target_data.target_as_param) == PPC)) { + /* + * Build an PPC crash binary on an PPC64 host. + */ + target_data.target = PPC; + } else if (name_to_target((char *)target_data.target_as_param) == + target_data.host) { + if ((target_data.initial_gdb_target != UNKNOWN) && + (target_data.host != target_data.initial_gdb_target)) + arch_mismatch(sp); + } else { + fprintf(stderr, + "\ntarget=%s is not supported on the %s host architecture\n\n", + target_data.target_as_param, + target_to_name(target_data.host)); + exit(1); + } + } + + /* + * Impose implied (sticky) target if an initial build has been + * done in the source tree. + */ + if (target_data.initial_gdb_target && + (target_data.target != target_data.initial_gdb_target)) { + if ((target_data.initial_gdb_target == ARM) && + (target_data.target != ARM)) { + if ((target_data.target == X86) || + (target_data.target == X86_64)) + target_data.target = ARM; + else + arch_mismatch(sp); + } + if ((target_data.target == ARM) && + (target_data.initial_gdb_target != ARM)) + arch_mismatch(sp); + + if ((target_data.initial_gdb_target == X86) && + (target_data.target != X86)) { + if (target_data.target == X86_64) + target_data.target = X86; + else + arch_mismatch(sp); + } + if ((target_data.target == X86) && + (target_data.initial_gdb_target != X86)) + arch_mismatch(sp); + + if ((target_data.initial_gdb_target == ARM64) && + (target_data.target != ARM64)) { + if (target_data.target == X86_64) + target_data.target = ARM64; + else + arch_mismatch(sp); + } + if ((target_data.target == ARM64) && + (target_data.initial_gdb_target != ARM64)) + arch_mismatch(sp); + + if ((target_data.initial_gdb_target == PPC) && + (target_data.target != PPC)) { + if (target_data.target == PPC64) + target_data.target = PPC; + else + arch_mismatch(sp); + } + if ((target_data.target == PPC) && + (target_data.initial_gdb_target != PPC)) + arch_mismatch(sp); + } + + if ((fp = fopen("Makefile", "r")) == NULL) { + perror("Makefile"); + goto get_release; + } + + while (fgets(buf, 512, fp)) { + if (strncmp(buf, "PROGRAM=", strlen("PROGRAM=")) == 0) { + p = strstr(buf, "=") + 1; + strip_linefeeds(p); + upper_case(p, target_data.program); + if (target_data.flags & DAEMON) + strcat(target_data.program, "D"); + continue; + } + } + + fclose(fp); + +get_release: + + target_data.release[0] = '\0'; + + if (file_exists(".rh_rpm_package")) { + if ((fp = fopen(".rh_rpm_package", "r")) == NULL) { + perror(".rh_rpm_package"); + } else { + if (fgets(buf, 512, fp)) { + strip_linefeeds(buf); + if (strlen(buf)) { + buf[MAXSTRLEN-1] = '\0'; + strcpy(target_data.release, buf); + } else + fprintf(stderr, + "WARNING: .rh_rpm_package file is empty!\n"); + } else + fprintf(stderr, + "WARNING: .rh_rpm_package file is empty!\n"); + fclose(fp); + + if (strlen(target_data.release)) + return; + } + } else + fprintf(stderr, + "WARNING: .rh_rpm_package file does not exist!\n"); + + if ((fp = fopen("defs.h", "r")) == NULL) { + perror("defs.h"); + return; + } + + while (fgets(buf, 512, fp)) { + if (strncmp(buf, "#define BASELEVEL_REVISION", + strlen("#define BASELEVEL_REVISION")) == 0) { + p = strstr(buf, "\"") + 1; + strip_linefeeds(p); + p[strlen(p)-1] = '\0'; + strcpy(target_data.release, p); + break; + } + } + + fclose(fp); +} + +void +show_configuration(void) +{ + int i; + + if (target_data.flags & QUIET) + return; + + switch (target_data.target) + { + case X86: + printf("TARGET: X86\n"); + break; + case ALPHA: + printf("TARGET: ALPHA\n"); + break; + case PPC: + printf("TARGET: PPC\n"); + break; + case IA64: + printf("TARGET: IA64\n"); + break; + case S390: + printf("TARGET: S390\n"); + break; + case S390X: + printf("TARGET: S390X\n"); + break; + case PPC64: + printf("TARGET: PPC64\n"); + break; + case X86_64: + printf("TARGET: X86_64\n"); + break; + case ARM: + printf("TARGET: ARM\n"); + break; + case ARM64: + printf("TARGET: ARM64\n"); + break; + } + + if (strlen(target_data.program)) { + for (i = 0; i < (strlen("TARGET")-strlen(target_data.program)); + i++) + printf(" "); + printf("%s: ", target_data.program); + if (strlen(target_data.release)) + printf("%s\n", target_data.release); + else + printf("???\n"); + } + + if (strlen(target_data.gdb_version)) + printf(" GDB: %s\n\n", &target_data.gdb_version[4]); +} + +void +build_configure(struct supported_gdb_version *sp) +{ + FILE *fp1, *fp2; + char buf[512]; + char *target; + char *target_CFLAGS; + char *gdb_conf_flags; + char *ldflags; + char *cflags; + + get_current_configuration(sp); + + target = target_CFLAGS = NULL; + + gdb_conf_flags = GDB_TARGET_DEFAULT; + switch (target_data.target) + { + case X86: + target = TARGET_X86; + if (target_data.host == X86_64) { + target_CFLAGS = TARGET_CFLAGS_X86_ON_X86_64; + gdb_conf_flags = GDB_TARGET_X86_ON_X86_64; + } else + target_CFLAGS = TARGET_CFLAGS_X86; + break; + case ALPHA: + target = TARGET_ALPHA; + target_CFLAGS = TARGET_CFLAGS_ALPHA; + break; + case PPC: + target = TARGET_PPC; + if (target_data.host == PPC64) { + target_CFLAGS = TARGET_CFLAGS_PPC_ON_PPC64; + gdb_conf_flags = GDB_TARGET_PPC_ON_PPC64; + } else + target_CFLAGS = TARGET_CFLAGS_PPC; + break; + case IA64: + target = TARGET_IA64; + target_CFLAGS = TARGET_CFLAGS_IA64; + break; + case S390: + target = TARGET_S390; + target_CFLAGS = TARGET_CFLAGS_S390; + break; + case S390X: + target = TARGET_S390X; + target_CFLAGS = TARGET_CFLAGS_S390X; + break; + case PPC64: + target = TARGET_PPC64; + target_CFLAGS = TARGET_CFLAGS_PPC64; + break; + case X86_64: + target = TARGET_X86_64; + target_CFLAGS = TARGET_CFLAGS_X86_64; + break; + case ARM: + target = TARGET_ARM; + if (target_data.host == X86) { + target_CFLAGS = TARGET_CFLAGS_ARM_ON_X86; + gdb_conf_flags = GDB_TARGET_ARM_ON_X86; + } else if (target_data.host == X86_64) { + target_CFLAGS = TARGET_CFLAGS_ARM_ON_X86_64; + gdb_conf_flags = GDB_TARGET_ARM_ON_X86_64; + } else + target_CFLAGS = TARGET_CFLAGS_ARM; + break; + case ARM64: + target = TARGET_ARM64; + if (target_data.host == X86_64) { + target_CFLAGS = TARGET_CFLAGS_ARM64_ON_X86_64; + gdb_conf_flags = GDB_TARGET_ARM64_ON_X86_64; + } else + target_CFLAGS = TARGET_CFLAGS_ARM64; + break; + } + + ldflags = get_extra_flags("LDFLAGS.extra", NULL); + cflags = get_extra_flags("CFLAGS.extra", NULL); + gdb_conf_flags = get_extra_flags("GDBFLAGS.extra", gdb_conf_flags); + + makefile_setup(&fp1, &fp2); + + while (fgets(buf, 512, fp1)) { + if (strncmp(buf, "TARGET=", strlen("TARGET=")) == 0) + fprintf(fp2, "%s\n", target); + else if (strncmp(buf, "TARGET_CFLAGS=", + strlen("TARGET_CFLAGS=")) == 0) + fprintf(fp2, "%s%s%s\n", target_CFLAGS, + cflags ? " " : "", cflags ? cflags : ""); + else if (strncmp(buf, "GDB_CONF_FLAGS=", + strlen("GDB_CONF_FLAGS=")) == 0) + fprintf(fp2, "%s\n", gdb_conf_flags); + else if (strncmp(buf, "GDB_FILES=",strlen("GDB_FILES=")) == 0) + fprintf(fp2, "%s\n", sp->GDB_FILES); + else if (strncmp(buf, "GDB_OFILES=",strlen("GDB_OFILES=")) == 0) + fprintf(fp2, "%s\n", sp->GDB_OFILES); + else if (strncmp(buf, "GDB_PATCH_FILES=",strlen("GDB_PATCH_FILES=")) == 0) + fprintf(fp2, "%s\n", sp->GDB_PATCH_FILES); + else if (strncmp(buf, "GDB_FLAGS=",strlen("GDB_FLAGS=")) == 0) + fprintf(fp2, "%s\n", sp->GDB_FLAGS); + else if (strncmp(buf, "GPL_FILES=", strlen("GPL_FILES=")) == 0) + fprintf(fp2, "GPL_FILES=%s\n", strcmp(sp->GPL, "GPLv2") == 0 ? + "COPYING" : "COPYING3"); + else if (strncmp(buf, "GDB=", strlen("GDB=")) == 0) { + fprintf(fp2, "%s\n", sp->GDB); + sprintf(target_data.gdb_version, "%s", &sp->GDB[4]); + } else if (strncmp(buf, "LDFLAGS=", strlen("LDFLAGS=")) == 0) { + fprintf(fp2, "LDFLAGS=%s\n", ldflags ? ldflags : ""); + } else + fprintf(fp2, "%s", buf); + + } + + makefile_create(&fp1, &fp2); + show_configuration(); + make_build_data(&target[strlen("TARGET=")]); +} + +void +release_configure(char *gdb_version, struct supported_gdb_version *sp) +{ + FILE *fp1, *fp2; + int found; + char buf[512]; + char gdb_files[MAXSTRLEN]; + + get_current_configuration(sp); + + sprintf(buf, "%s/gdb", gdb_version); + if (!file_exists(buf)) { + fprintf(stderr, "make release: no such directory: %s\n", buf); + exit(1); + } + sprintf(gdb_files, "GDB_%s_FILES", + &gdb_version[strlen("gdb-")]); + + makefile_setup(&fp1, &fp2); + + found = 0; + while (fgets(buf, 512, fp1)) { + if (strncmp(buf, gdb_files, strlen(gdb_files)) == 0) + found++; + if (strncmp(buf, "GDB_FILES=", strlen("GDB_FILES=")) == 0) + fprintf(fp2, "GDB_FILES=${%s}\n", gdb_files); + else if (strncmp(buf, "VERSION=", strlen("VERSION=")) == 0) + fprintf(fp2, "VERSION=%s\n", + target_data.release); + else if (strncmp(buf, "GDB_PATCH_FILES=", strlen("GDB_PATCH_FILES=")) == 0) + fprintf(fp2, "%s\n", sp->GDB_PATCH_FILES); + else if (strncmp(buf, "GPL_FILES=", strlen("GPL_FILES=")) == 0) + fprintf(fp2, "GPL_FILES=%s\n", strcmp(sp->GPL, "GPLv2") == 0 ? + "COPYING" : "COPYING3"); + else + fprintf(fp2, "%s", buf); + + } + + if (!found) { + fprintf(stderr, "make release: cannot find %s\n", gdb_files); + exit(1); + } + + makefile_create(&fp1, &fp2); +} + +/* + * Create an .rh_rpm_package file if the passed-in variable is set. + */ +void +make_rh_rpm_package(char *package, int release) +{ + char *p, *cur; + FILE *fp; + char buf[256]; + + if ((strcmp(package, "remove") == 0)) { + if (file_exists(".rh_rpm_package")) { + if (unlink(".rh_rpm_package")) { + perror("unlink"); + fprintf(stderr, + "cannot remove .rh_rpm_package\n"); + exit(1); + } + } + return; + } + + if (!(p = strstr(package, "="))) + return; + + if (!strlen(++p)) + return; + + if (release) { + if (!(fp = popen("./crash -v", "r"))) { + fprintf(stderr, "cannot execute \"crash -v\"\n"); + exit(1); + } + cur = NULL; + while (fgets(buf, 256, fp)) { + if (strncmp(buf, "crash ", 6) == 0) { + cur = &buf[6]; + break; + } + } + pclose(fp); + + if (!cur) { + fprintf(stderr, "cannot get version from \"crash -v\"\n"); + exit(1); + } + strip_linefeeds(cur); + + if (strcmp(cur, p) != 0) { + fprintf(stderr, "./crash version: %s\n", cur); + fprintf(stderr, "release version: %s\n", p); + exit(1); + } + } + + if ((fp = fopen(".rh_rpm_package", "w")) == NULL) { + perror("fopen"); + fprintf(stderr, "cannot open .rh_rpm_package\n"); + exit(1); + } + + fprintf(fp, "%s\n", strip_linefeeds(p)); + + fclose(fp); +} + +void +gdb_configure(struct supported_gdb_version *sp) +{ + FILE *fp1, *fp2; + char buf[512]; + + get_current_configuration(sp); + + makefile_setup(&fp1, &fp2); + + while (fgets(buf, 512, fp1)) { + if (strncmp(buf, "GDB=", strlen("GDB=")) == 0) + fprintf(fp2, "%s\n", sp->GDB); + else + fprintf(fp2, "%s", buf); + + } + + makefile_create(&fp1, &fp2); +} + +void +unconfigure(void) +{ + FILE *fp1, *fp2; + char buf[512]; + + makefile_setup(&fp1, &fp2); + + while (fgets(buf, 512, fp1)) { + if (strncmp(buf, "TARGET=", strlen("TARGET=")) == 0) + fprintf(fp2, "TARGET=\n"); + else if (strncmp(buf, "TARGET_CFLAGS=", + strlen("TARGET_CFLAGS=")) == 0) + fprintf(fp2, "TARGET_CFLAGS=\n"); + else if (strncmp(buf, "GDB_CONF_FLAGS=", + strlen("GDB_CONF_FLAGS=")) == 0) + fprintf(fp2, "GDB_CONF_FLAGS=\n"); + else if (strncmp(buf, "GDB_FILES=",strlen("GDB_FILES=")) == 0) + fprintf(fp2, "GDB_FILES=\n"); + else if (strncmp(buf, "GDB_OFILES=",strlen("GDB_OFILES=")) == 0) + fprintf(fp2, "GDB_OFILES=\n"); + else if (strncmp(buf, "GDB_PATCH_FILES=",strlen("GDB_PATCH_FILES=")) == 0) + fprintf(fp2, "GDB_PATCH_FILES=\n"); + else if (strncmp(buf, "GDB_FLAGS=",strlen("GDB_FLAGS=")) == 0) + fprintf(fp2, "GDB_FLAGS=\n"); + else if (strncmp(buf, "GDB=", strlen("GDB=")) == 0) + fprintf(fp2, "GDB=\n"); + else if (strncmp(buf, "VERSION=", strlen("VERSION=")) == 0) + fprintf(fp2, "VERSION=\n"); + else if (strncmp(buf, "GPL_FILES=", strlen("GPL_FILES=")) == 0) + fprintf(fp2, "GPL_FILES=\n"); + else if (strncmp(buf, "LDFLAGS=", strlen("LDFLAGS=")) == 0) + fprintf(fp2, "LDFLAGS=\n"); + else if (strncmp(buf, "WARNING_ERROR=", + strlen("WARNING_ERROR=")) == 0) { + shift_string_right(buf, 1); + buf[0] = '#'; + fprintf(fp2, "%s", buf); + } else if (strncmp(buf, "WARNING_OPTIONS=", + strlen("WARNING_OPTIONS=")) == 0) { + shift_string_right(buf, 1); + buf[0] = '#'; + fprintf(fp2, "%s", buf); + } else + fprintf(fp2, "%s", buf); + } + + makefile_create(&fp1, &fp2); +} + +void +set_warnings(int w) +{ + FILE *fp1, *fp2; + char buf[512]; + + makefile_setup(&fp1, &fp2); + + while (fgets(buf, 512, fp1)) { + if (strncmp(buf, "#WARNING_ERROR=", + strlen("#WARNING_ERROR=")) == 0) { + switch (w) + { + case 'W': + shift_string_left(buf, 1); + break; + case 'w': + case 'n': + break; + } + } + + if (strncmp(buf, "WARNING_ERROR=", + strlen("WARNING_ERROR=")) == 0) { + switch (w) + { + case 'n': + case 'w': + shift_string_right(buf, 1); + buf[0] = '#'; + break; + case 'W': + break; + } + } + + if (strncmp(buf, "#WARNING_OPTIONS=", + strlen("#WARNING_OPTIONS=")) == 0) { + switch (w) + { + case 'W': + case 'w': + shift_string_left(buf, 1); + break; + case 'n': + break; + } + } + + if (strncmp(buf, "WARNING_OPTIONS=", + strlen("WARNING_OPTIONS=")) == 0) { + switch (w) + { + case 'w': + case 'W': + break; + case 'n': + shift_string_right(buf, 1); + buf[0] = '#'; + break; + } + } + + fprintf(fp2, "%s", buf); + } + + makefile_create(&fp1, &fp2); +} + +void +makefile_setup(FILE **fp1, FILE **fp2) +{ + if (stat("Makefile", &target_data.statbuf) == -1) { + perror("Makefile"); + exit(1); + } + + if ((*fp1 = fopen("Makefile", "r")) == NULL) { + perror("fopen"); + fprintf(stderr, "cannot open existing Makefile\n"); + exit(1); + } + + unlink("Makefile.new"); + if ((*fp2 = fopen("Makefile.new", "w+")) == NULL) { + perror("fopen"); + fprintf(stderr, "cannot create new Makefile\n"); + exit(1); + } +} + +void +makefile_create(FILE **fp1, FILE **fp2) +{ + fclose(*fp1); + fclose(*fp2); + + if (system("mv Makefile.new Makefile") != 0) { + fprintf(stderr, "Makefile: cannot create new Makefile\n"); + fprintf(stderr, "please copy Makefile.new to Makefile\n"); + exit(1); + } + + if (chown("Makefile", target_data.statbuf.st_uid, + target_data.statbuf.st_gid) == -1) { + fprintf(stderr, + "Makefile: cannot restore original owner/group\n"); + } +} + + + +#define LASTCHAR(s) (s[strlen(s)-1]) + +char * +strip_linefeeds(char *line) +{ + char *p; + + if (line == NULL || strlen(line) == 0) + return(line); + + p = &LASTCHAR(line); + + while (*p == '\n') + *p = '\0'; + + return(line); +} + +/* + * Turn a string into upper-case. + */ +char * +upper_case(char *s, char *buf) +{ + char *p1, *p2; + + p1 = s; + p2 = buf; + + while (*p1) { + *p2 = toupper(*p1); + p1++, p2++; + } + + *p2 = '\0'; + + return(buf); +} + +/* + * Turn a string into lower-case. + */ +char * +lower_case(char *s, char *buf) +{ + char *p1, *p2; + + p1 = s; + p2 = buf; + + while (*p1) { + *p2 = tolower(*p1); + p1++, p2++; + } + + *p2 = '\0'; + + return(buf); +} + +char * +shift_string_left(char *s, int cnt) +{ + int origlen; + + if (!cnt) + return(s); + + origlen = strlen(s); + memmove(s, s+cnt, (origlen-cnt)); + *(s+(origlen-cnt)) = '\0'; + return(s); +} + +char * +shift_string_right(char *s, int cnt) +{ + int i; + int origlen; + + if (!cnt) + return(s); + + origlen = strlen(s); + memmove(s+cnt, s, origlen); + *(s+(origlen+cnt)) = '\0'; + + for (i = 0; i < cnt; i++) + s[i] = ' '; + + return(s); +} + +char * +strip_beginning_whitespace(char *line) +{ + char buf[MAXSTRLEN]; + char *p; + + if (line == NULL || strlen(line) == 0) + return(line); + + strcpy(buf, line); + p = &buf[0]; + while (*p == ' ' || *p == '\t') + p++; + strcpy(line, p); + + return(line); +} + +char * +strip_ending_whitespace(char *line) +{ + char *p; + + if (line == NULL || strlen(line) == 0) + return(line); + + p = &line[strlen(line)-1]; + + while (*p == ' ' || *p == '\t') { + *p = '\0'; + if (p == line) + break; + p--; + } + + return(line); +} + +int +file_exists(char *file) +{ + struct stat sbuf; + + if (stat(file, &sbuf) == 0) + return TRUE; + + return FALSE; +} + +int +count_chars(char *s, char c) +{ + char *p; + int count; + + if (!s) + return 0; + + count = 0; + + for (p = s; *p; p++) { + if (*p == c) + count++; + } + + return count; +} + + +void +make_build_data(char *target) +{ + char *p; + char hostname[MAXSTRLEN]; + char progname[MAXSTRLEN]; + char inbuf1[MAXSTRLEN]; + char inbuf2[MAXSTRLEN]; + char inbuf3[MAXSTRLEN]; + FILE *fp1, *fp2, *fp3, *fp4; + + unlink("build_data.c"); + + fp1 = popen("date", "r"); + fp2 = popen("id", "r"); + fp3 = popen("gcc --version", "r"); + + if ((fp4 = fopen("build_data.c", "w")) == NULL) { + perror("build_data.c"); + exit(1); + } + + if (gethostname(hostname, MAXSTRLEN) != 0) + hostname[0] = '\0'; + + p = fgets(inbuf1, 79, fp1); + + p = fgets(inbuf2, 79, fp2); + p = strstr(inbuf2, ")"); + p++; + *p = '\0'; + + p = fgets(inbuf3, 79, fp3); + + lower_case(target_data.program, progname); + + fprintf(fp4, "char *build_command = \"%s\";\n", progname); + if (strlen(hostname)) + fprintf(fp4, "char *build_data = \"%s by %s on %s\";\n", + strip_linefeeds(inbuf1), inbuf2, hostname); + else + fprintf(fp4, "char *build_data = \"%s by %s\";\n", + strip_linefeeds(inbuf1), inbuf2); + + bzero(inbuf1, MAXSTRLEN); + sprintf(inbuf1, "%s", target_data.release); + + fprintf(fp4, "char *build_target = \"%s\";\n", target); + + fprintf(fp4, "char *build_version = \"%s\";\n", inbuf1); + + fprintf(fp4, "char *compiler_version = \"%s\";\n", + strip_linefeeds(inbuf3)); + + pclose(fp1); + pclose(fp2); + pclose(fp3); + fclose(fp4); +} + +void +make_spec_file(struct supported_gdb_version *sp) +{ + char *Version, *Release; + char buf[512]; + + get_current_configuration(sp); + + Release = strstr(target_data.release, "-"); + if (!Release) { + Version = target_data.release; + Release = "0"; + } else { + fprintf(stderr, + "crash.spec: obsolete src.rpm build manner -- no dashes allowed: %s\n", + target_data.release); + return; + } + + printf("#\n"); + printf("# crash core analysis suite\n"); + printf("#\n"); + printf("Summary: crash utility for live systems; netdump, diskdump, kdump, LKCD or mcore dumpfiles\n"); + printf("Name: %s\n", lower_case(target_data.program, buf)); + printf("Version: %s\n", Version); + printf("Release: %s\n", Release); + printf("License: %s\n", sp->GPL); + printf("Group: Development/Debuggers\n"); + printf("Source: %%{name}-%%{version}.tar.gz\n"); + printf("URL: http://people.redhat.com/anderson\n"); + printf("Distribution: Linux 2.2 or greater\n"); + printf("Vendor: Red Hat, Inc.\n"); + printf("Packager: Dave Anderson \n"); + printf("ExclusiveOS: Linux\n"); + printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64\n"); + printf("Buildroot: %%{_tmppath}/%%{name}-root\n"); + printf("BuildRequires: ncurses-devel zlib-devel bison\n"); + printf("Requires: binutils\n"); + printf("# Patch0: crash-3.3-20.installfix.patch (patch example)\n"); + printf("\n"); + printf("%%description\n"); + printf("The core analysis suite is a self-contained tool that can be used to\n"); + printf("investigate either live systems, kernel core dumps created from the\n"); + printf("netdump, diskdump and kdump facilities from Red Hat Linux, the mcore kernel patch\n"); + printf("offered by Mission Critical Linux, or the LKCD kernel patch.\n"); + printf("\n"); + printf("%%package devel\n"); + printf("Requires: %%{name} = %%{version}, zlib-devel\n"); + printf("Summary: crash utility for live systems; netdump, diskdump, kdump, LKCD or mcore dumpfiles\n"); + printf("Group: Development/Debuggers\n"); + printf("\n"); + printf("%%description devel\n"); + printf("The core analysis suite is a self-contained tool that can be used to\n"); + printf("investigate either live systems, kernel core dumps created from the\n"); + printf("netdump, diskdump and kdump packages from Red Hat Linux, the mcore kernel patch\n"); + printf("offered by Mission Critical Linux, or the LKCD kernel patch.\n"); + printf("\n"); + printf("%%package extensions\n"); + printf("Summary: Additional commands for the crash dump analysis tool\n"); + printf("Group: Development/Debuggers\n"); + printf("\n"); + printf("%%description extensions\n"); + printf("The extensions package contains plugins that provide additional crash\n"); + printf("commands. The extensions can be loaded in crash via the \"extend\" command.\n"); + printf("\n"); + printf("The following extensions are provided:\n"); + printf("* eppic: Provides C-like language for writing dump analysis scripts\n"); + printf("* dminfo: Device-mapper target analyzer\n"); + printf("* snap: Takes a snapshot of live memory and creates a kdump dumpfile\n"); + printf("* trace: Displays kernel tracing data and traced events that occurred prior to a panic.\n"); + printf("\n"); + printf("%%prep\n"); + printf("%%setup -n %%{name}-%%{version}\n"); + printf("# %%patch0 -p1 -b .install (patch example)\n"); + printf("\n"); + printf("%%build\n"); + printf("make RPMPKG=\"%%{version}\"\n"); + printf("# make RPMPKG=\"%%{version}-%%{release}\"\n"); + printf("make extensions\n"); + /* printf("make crashd\n"); */ + printf("\n"); + printf("%%install\n"); + printf("rm -rf %%{buildroot}\n"); + printf("mkdir -p %%{buildroot}/usr/bin\n"); + printf("make DESTDIR=%%{buildroot} install\n"); + printf("mkdir -p %%{buildroot}%%{_mandir}/man8\n"); + printf("cp crash.8 %%{buildroot}%%{_mandir}/man8/crash.8\n"); + printf("mkdir -p %%{buildroot}%%{_includedir}/crash\n"); + printf("cp defs.h %%{buildroot}%%{_includedir}/crash\n"); + printf("mkdir -p %%{buildroot}%%{_libdir}/crash/extensions\n"); + printf("if [ -f extensions/eppic.so ]\n"); + printf("then\n"); + printf("cp extensions/eppic.so %%{buildroot}%%{_libdir}/crash/extensions\n"); + printf("fi\n"); + printf("cp extensions/dminfo.so %%{buildroot}%%{_libdir}/crash/extensions\n"); + printf("cp extensions/snap.so %%{buildroot}%%{_libdir}/crash/extensions\n"); + printf("cp extensions/trace.so %%{buildroot}%%{_libdir}/crash/extensions\n"); + printf("\n"); + printf("%%clean\n"); + printf("rm -rf %%{buildroot}\n"); + printf("\n"); + printf("%%files\n"); + printf("%%defattr(-,root,root)\n"); + printf("/usr/bin/crash\n"); + printf("%%{_mandir}/man8/crash.8*\n"); + /* printf("/usr/bin/crashd\n"); */ + printf("%%doc README\n"); + printf("\n"); + printf("%%files devel\n"); + printf("%%defattr(-,root,root)\n"); + printf("%%{_includedir}/*\n"); + printf("\n"); + printf("%%files extensions\n"); + printf("%%defattr(-,root,root)\n"); + printf("%%{_libdir}/crash/extensions/*\n"); +} + +/* + * Use the default gdb #defines unless there's a .gdb file. + */ +struct supported_gdb_version * +setup_gdb_defaults(void) +{ + FILE *fp; + char inbuf[512]; + char buf[512]; + struct supported_gdb_version *sp; + + /* + * Use the default, allowing for an override in .gdb + */ + if (!file_exists(".gdb")) + return store_gdb_defaults(NULL); + + if ((fp = fopen(".gdb", "r")) == NULL) { + perror(".gdb"); + return store_gdb_defaults(NULL); + } + + while (fgets(inbuf, 512, fp)) { + strip_linefeeds(inbuf); + strip_beginning_whitespace(inbuf); + + strcpy(buf, inbuf); + + /* + * Simple override. + */ + if (strcmp(buf, "5.3") == 0) { + fclose(fp); + sp = &supported_gdb_versions[GDB_5_3]; + fprintf(stderr, ".gdb configuration: %s\n\n", sp->GDB_VERSION_IN); + return store_gdb_defaults(sp); + } + if (strcmp(buf, "6.0") == 0) { + fclose(fp); + sp = &supported_gdb_versions[GDB_6_0]; + fprintf(stderr, ".gdb configuration: %s\n\n", sp->GDB_VERSION_IN); + return store_gdb_defaults(sp); + } + if (strcmp(buf, "6.1") == 0) { + fclose(fp); + sp = &supported_gdb_versions[GDB_6_1]; + fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); + return store_gdb_defaults(sp); + } + if (strcmp(buf, "7.0") == 0) { + fclose(fp); + sp = &supported_gdb_versions[GDB_7_0]; + fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); + return store_gdb_defaults(sp); + } + if (strcmp(buf, "7.3.1") == 0) { + fclose(fp); + sp = &supported_gdb_versions[GDB_7_3_1]; + fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); + return store_gdb_defaults(sp); + } + if (strcmp(buf, "7.6") == 0) { + fclose(fp); + sp = &supported_gdb_versions[GDB_7_6]; + fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); + return store_gdb_defaults(sp); + } + + } + + fclose(fp); + + fprintf(stderr, ".gdb: rejected -- using default gdb\n\n"); + return store_gdb_defaults(NULL); +} + +struct supported_gdb_version * +store_gdb_defaults(struct supported_gdb_version *sp) +{ + if (!sp) + sp = &supported_gdb_versions[default_gdb]; + else + fprintf(stderr, "WARNING: \"make clean\" may be required before rebuilding\n\n"); + + return sp; +} + +void +set_initial_target(struct supported_gdb_version *sp) +{ + FILE *fp; + char crash_target[512]; + char buf[512]; + + target_data.initial_gdb_target = UNKNOWN; + + sprintf(crash_target, "%s/crash.target", + &sp->GDB[strlen("GDB=")]); + + if (!file_exists(crash_target)) { + if (target_data.target_as_param && + file_exists(&sp->GDB[strlen("GDB=")])) { + fprintf(stderr, + "\nThe \"%s\" file does not exist.\n", + crash_target); + target_rebuild_instructions(sp, (char *)target_data.target_as_param); + exit(1); + } + return; + } + + if ((fp = fopen(crash_target, "r")) == NULL) { + perror(crash_target); + return; + } + + if (!fgets(buf, 512, fp)) { + perror(crash_target); + fclose(fp); + return; + } + + fclose(fp); + + if (strncmp(buf, "X86_64", strlen("X86_64")) == 0) + target_data.initial_gdb_target = X86_64; + else if (strncmp(buf, "X86", strlen("X86")) == 0) + target_data.initial_gdb_target = X86; + else if (strncmp(buf, "ALPHA", strlen("ALPHA")) == 0) + target_data.initial_gdb_target = ALPHA; + else if (strncmp(buf, "PPC64", strlen("PPC64")) == 0) + target_data.initial_gdb_target = PPC64; + else if (strncmp(buf, "PPC", strlen("PPC")) == 0) + target_data.initial_gdb_target = PPC; + else if (strncmp(buf, "IA64", strlen("IA64")) == 0) + target_data.initial_gdb_target = IA64; + else if (strncmp(buf, "S390X", strlen("S390X")) == 0) + target_data.initial_gdb_target = S390X; + else if (strncmp(buf, "S390", strlen("S390")) == 0) + target_data.initial_gdb_target = S390; + else if (strncmp(buf, "ARM64", strlen("ARM64")) == 0) + target_data.initial_gdb_target = ARM64; + else if (strncmp(buf, "ARM", strlen("ARM")) == 0) + target_data.initial_gdb_target = ARM; +} + +char * +target_to_name(int target) +{ + switch (target) + { + case X86: return("X86"); + case ALPHA: return("ALPHA"); + case PPC: return("PPC"); + case IA64: return("IA64"); + case S390: return("S390"); + case S390X: return("S390X"); + case PPC64: return("PPC64"); + case X86_64: return("X86_64"); + case ARM: return("ARM"); + case ARM64: return("ARM64"); + } + + return "UNKNOWN"; +} + +int +name_to_target(char *name) +{ + if (strncmp(name, "X86_64", strlen("X86_64")) == 0) + return X86_64; + else if (strncmp(name, "x86_64", strlen("x86_64")) == 0) + return X86_64; + else if (strncmp(name, "X86", strlen("X86")) == 0) + return X86; + else if (strncmp(name, "x86", strlen("x86")) == 0) + return X86; + else if (strncmp(name, "ALPHA", strlen("ALPHA")) == 0) + return ALPHA; + else if (strncmp(name, "alpha", strlen("alpha")) == 0) + return ALPHA; + else if (strncmp(name, "PPC64", strlen("PPC64")) == 0) + return PPC64; + else if (strncmp(name, "ppc64", strlen("ppc64")) == 0) + return PPC64; + else if (strncmp(name, "PPC", strlen("PPC")) == 0) + return PPC; + else if (strncmp(name, "ppc", strlen("ppc")) == 0) + return PPC; + else if (strncmp(name, "IA64", strlen("IA64")) == 0) + return IA64; + else if (strncmp(name, "ia64", strlen("ia64")) == 0) + return IA64; + else if (strncmp(name, "S390X", strlen("S390X")) == 0) + return S390X; + else if (strncmp(name, "s390x", strlen("s390x")) == 0) + return S390X; + else if (strncmp(name, "S390", strlen("S390")) == 0) + return S390; + else if (strncmp(name, "s390", strlen("s390")) == 0) + return S390; + else if (strncmp(name, "ARM64", strlen("ARM64")) == 0) + return ARM64; + else if (strncmp(name, "arm64", strlen("arm64")) == 0) + return ARM64; + else if (strncmp(name, "aarch64", strlen("aarch64")) == 0) + return ARM64; + else if (strncmp(name, "ARM", strlen("ARM")) == 0) + return ARM; + else if (strncmp(name, "arm", strlen("arm")) == 0) + return ARM; + + return UNKNOWN; +} + +char * +get_extra_flags(char *filename, char *initial) +{ + FILE *fp; + char inbuf[512]; + char buf[512]; + + if (!file_exists(filename)) + return (initial ? initial : NULL); + + if ((fp = fopen(filename, "r")) == NULL) { + perror(filename); + return (initial ? initial : NULL); + } + + if (initial) + strcpy(buf, initial); + else + buf[0] = '\0'; + + while (fgets(inbuf, 512, fp)) { + strip_linefeeds(inbuf); + strip_beginning_whitespace(inbuf); + strip_ending_whitespace(inbuf); + if (inbuf[0] == '#') + continue; + if (strlen(inbuf)) { + if (strlen(buf)) + strcat(buf, " "); + strcat(buf, inbuf); + } + } + + fclose(fp); + + if (strlen(buf)) + return strdup(buf); + else + return NULL; +} + +/* + * Add extra compression libraries. If not already there, create + * a CFLAGS.extra file and an LDFLAGS.extra file. + + * For lzo: + * - enter -DSNAPPY in the CFLAGS.extra file + * - enter -lsnappy in the LDFLAGS.extra file + * + * For snappy: + * - enter -DLZO in the CFLAGS.extra file + * - enter -llzo2 in the LDFLAGS.extra file. + */ +void +add_extra_lib(char *option) +{ + int lzo, add_DLZO, add_llzo2; + int snappy, add_DSNAPPY, add_lsnappy; + char *cflags, *ldflags; + FILE *fp_cflags, *fp_ldflags; + char *mode; + char inbuf[512]; + + lzo = add_DLZO = add_llzo2 = 0; + snappy = add_DSNAPPY = add_lsnappy = 0; + + ldflags = get_extra_flags("LDFLAGS.extra", NULL); + cflags = get_extra_flags("CFLAGS.extra", NULL); + + if (strcmp(option, "lzo") == 0) { + lzo++; + if (!cflags || !strstr(cflags, "-DLZO")) + add_DLZO++; + if (!ldflags || !strstr(ldflags, "-llzo2")) + add_llzo2++; + } + + if (strcmp(option, "snappy") == 0) { + snappy++; + if (!cflags || !strstr(cflags, "-DSNAPPY")) + add_DSNAPPY++; + if (!ldflags || !strstr(ldflags, "-lsnappy")) + add_lsnappy++; + } + + if ((lzo || snappy) && + file_exists("diskdump.o") && (unlink("diskdump.o") < 0)) { + perror("diskdump.o"); + return; + } + + mode = file_exists("CFLAGS.extra") ? "r+" : "w+"; + if ((fp_cflags = fopen("CFLAGS.extra", mode)) == NULL) { + perror("CFLAGS.extra"); + return; + } + + mode = file_exists("LDFLAGS.extra") ? "r+" : "w+"; + if ((fp_ldflags = fopen("LDFLAGS.extra", mode)) == NULL) { + perror("LDFLAGS.extra"); + fclose(fp_cflags); + return; + } + + if (add_DLZO || add_DSNAPPY) { + while (fgets(inbuf, 512, fp_cflags)) + ; + if (add_DLZO) + fputs("-DLZO\n", fp_cflags); + if (add_DSNAPPY) + fputs("-DSNAPPY\n", fp_cflags); + } + + if (add_llzo2 || add_lsnappy) { + while (fgets(inbuf, 512, fp_ldflags)) + ; + if (add_llzo2) + fputs("-llzo2\n", fp_ldflags); + if (add_lsnappy) + fputs("-lsnappy\n", fp_ldflags); + } + + fclose(fp_cflags); + fclose(fp_ldflags); +} diff --git a/crash.8 b/crash.8 new file mode 100644 index 00000000..8eacacb2 --- /dev/null +++ b/crash.8 @@ -0,0 +1,830 @@ +.\" +.de CO +\dB\\$1\fP \fI\\$2\fP +.. +.TH CRASH 8 +.SH NAME +crash \- Analyze Linux crash dump data or a live system +.SH SYNOPSIS +.B crash +[\fIOPTION\fR]... \fINAMELIST MEMORY-IMAGE (dumpfile form)\fR +.br +.B crash +[\fIOPTION\fR]... \fI[NAMELIST] (live system form)\fR +.SH DESCRIPTION +.B Crash +is a tool for interactively analyzing the state of the Linux system +while it is running, or after a kernel crash has occurred and a +core dump has been created by the +.I netdump, +.I diskdump, +.I LKCD, +.I kdump, +.I xendump +or +.I kvmdump +facilities. It is loosely based on the SVR4 UNIX crash +command, but has been significantly enhanced +by completely merging it with the +.B gdb(1) +debugger. The marriage of the two effectively combines the +kernel-specific nature of the traditional UNIX crash utility with the +source code level debugging capabilities of +.B gdb(1). + +In the +.I dumpfile form, +both a NAMELIST and a MEMORY-IMAGE argument must be entered. +In the +.I live system form, +the NAMELIST argument must be entered if +the kernel's +.I vmlinux +file is not +located in a known location, such as the +.I /usr/lib/debug/lib/modules/ +directory. + +The +.B crash +utility has also been extended to support the analysis +of dumpfiles generated by a crash of the Xen hypervisor. In that +case, the NAMELIST argument must be that of the +.I xen-syms +binary. +Live system analysis is not supported for the Xen hypervisor. + +The +.B crash +utility command set consists of common kernel core analysis tools +such as kernel stack back traces of all processes, source code disassembly, +formatted kernel structure and variable displays, virtual memory data, +dumps of linked-lists, etc., along with several commands that delve +deeper into specific kernel subsystems. Appropriate +.B gdb +commands may also be entered, which in +turn are passed on to the +.B gdb +module for execution. +If desired, commands may be placed in either a +.I $HOME/.crashrc +file and/or in a +.I .crashrc +file in the current directory. +During initialization, the commands in +.I $HOME/.crashrc +are executed first, followed by those in the +.I ./.crashrc +file. + +The +.B crash +utility is designed to be independent of Linux version +dependencies. When new kernel source code impacts the +correct functionality of +.B crash +and its command set, the utility will +be updated to recognize new kernel code changes, while +maintaining backwards compatibility with earlier releases. +.SH OPTIONS +.de BS +\fB\\$1\fP\ \fR\\$2\fP +.. +.TP +.BI NAMELIST +This is a pathname to an uncompressed kernel image +(a +.I vmlinux +file), or a Xen hypervisor image (a +.I xen-syms +file) +which has been compiled with the "-g" option. +If using the +.I dumpfile form, +a +.I vmlinux +file may be compressed in either gzip or bzip2 formats. +.TP +.BI MEMORY-IMAGE +A kernel core dump file created by the +.I netdump, +.I diskdump, +.I LKCD +.I kdump, +.I xendump +or +.I kvmdump +facilities. + +If a MEMORY-IMAGE argument is not entered, the session will be invoked on +the live system, which typically requires root privileges because of +the device file used to access system RAM. By default, +.I /dev/crash +will be used if it exists. If it does not exist, then +.I /dev/mem +will be used; but if the kernel has been configured +with +.B CONFIG_STRICT_DEVMEM, +then +.I /proc/kcore +will be used. +It is permissible to explicitly enter +.I /dev/crash, +.I /dev/mem +or +.I /proc/kcore. +.TP +.BI mapfile +If the NAMELIST file is not the same kernel that is +running (live system form), or the kernel that was running +when the system crashed (dumpfile form), then the +.I System.map +file of the original kernel should be entered on the command line. +.P +.BI -h \ [option] +.br +.BI \--help \ [option] +.RS +Without an +.I option +argument, display a +.B crash +usage help message. If the +.I option +argument is a +.B crash +command name, the help page for that command is displayed. If it is +the string "input", a page describing the various +.B crash +command line input options is displayed. If it is the string "output", a +page describing command line output options is displayed. +If it is the string "all", then all of the possible help messages +are displayed. After the help message is displayed, +.B crash +exits. +.RE +.TP +.B \-s +Silently proceed directly to the "crash>" prompt without displaying +any version, GPL, or +.B crash +initialization data during startup, and by default, runtime command +output is not passed to any scrolling command. +.TP +.BI \-i \ file +Execute the command(s) contained in +.I file +prior to displaying the "crash>" prompt for interactive +user input. +.TP +.BI \-d \ num +Set the internal debug level. +The higher the number, the more debugging data will be printed when +.B crash +initializes and runs. +.TP +.B \-S +Use +.I /boot/System.map +as the +.I mapfile\fP. +.TP +.B \-e \fIvi | emacs\fR +Set the +.B readline(3) +command line editing mode to "vi" or "emacs". The default +editing mode is "vi". +.TP +.B \-f +Force the usage of a compressed +.I vmlinux +file if its original name +does not start with "vmlinux". +.TP +.B \-k +Indicate that the NAMELIST file is an LKCD "Kerntypes" debuginfo file. +.TP +.BI -g \ [namelist] +Determine if a +.I vmlinux +or +.I xen-syms +namelist file contains debugging data. +.TP +.B \-t +Display the system-crash timestamp and exit. +.TP +.B \-L +Attempt to lock all of its virtual address space into memory by calling mlockall(MCL_CURRENT|MCL_FUTURE) +during initialization. If the system call fails, an error message will be displayed, +but the session continues. +.TP +.BI \-c \ tty-device +Open the +.I tty-device +as the console used for debug messages. +.TP +.BI \-p \ page-size +If a processor's page size cannot be determined by the dumpfile, +and the processor default cannot be used, use +.I page-size. +.P +.B -m \fIoption=value\fR +.br +.B --machdep \fIoption=value\fR +.RS +Pass an option and value pair to machine-dependent code. These +architecture-specific option/pairs should only be +required in very rare circumstances: +.P +.nf +X86_64: + physbase= + irq_eframe_link= + max_physmem_bits= + vm=orig (pre-2.6.11 virtual memory address ranges) + vm=2.6.11 (2.6.11 and later virtual memory address ranges) + vm=xen (Xen kernel virtual memory address ranges) + vm=xen-rhel4 (RHEL4 Xen kernel virtual address ranges) +PPC64: + vm=orig + vm=2.6.14 (4-level page tables) +IA64: + phys_start= + init_stack_size= + vm=4l (4-level page tables) +ARM: + physbase= +.fi +.RE +.TP +.B \-x +Automatically load extension modules from a particular directory. +If a directory is specified in the +.B CRASH_EXTENSIONS +shell environment +variable, then that directory will be used. Otherwise +.I /usr/lib64/crash/extensions +(64-bit architectures) or +.I /usr/lib/crash/extensions +(32-bit architectures) will be used; +if they do not exist, then the +.I ./extensions directory will be used. +.TP +.BI --active +Track only the active task on each cpu. +.TP +.BI --buildinfo +Display the crash binary's build date, the user ID of the builder, +the hostname of the machine where the build was done, the target +architecture, the version number, and the compiler version. +.TP +.BI --memory_module \ modname +Use the +.I modname +as an alternative kernel module to the +.I crash.ko +module that creates the +.I /dev/crash +device. +.TP +.BI --memory_device \ device +Use +.I device +as an alternative device to the +.I /dev/crash, /dev/mem +or +.I /proc/kcore +devices. +.TP +.B --log dumpfile +Dump the contents of the kernel log buffer. A kernel namelist +argument is not necessary, but the dumpfile must contain the +VMCOREINFO data taken from the original /proc/vmcore ELF header. +.TP +.B --no_kallsyms +Do not use kallsyms-generated symbol information contained within +kernel module object files. +.TP +.B --no_modules +Do not access or display any kernel module related information. +.TP +.B --no_ikconf +Do not attempt to read configuration data that was built into kernels +configured with +.B CONFIG_IKCONFIG. +.TP +.B --no_data_debug +Do not verify the validity of all structure member offsets and structure +sizes that it uses. +.TP +.B --no_kmem_cache +Do not initialize the kernel's slab cache infrastructure, and commands that +use kmem_cache-related data will not work. +.TP +.B --no_elf_notes +Do not use the registers from the ELF NT_PRSTATUS notes saved in a compressed kdump header +for backtraces. +.TP +.B --kmem_cache_delay +Delay the initialization of the kernel's slab cache infrastructure until +it is required by a run-time command. +.TP +.B --readnow +Pass this flag to the embedded +.B gdb +module, which will override its two-stage strategy that it uses for reading +symbol tables from the NAMELIST. +.TP +.B --smp +Specify that the system being analyzed is an SMP kernel. +.P +.B -v +.br +.B --version +.RS +Display the version of the +.B crash +utility, the version of the embedded +.B gdb +module, GPL information, and copyright notices. +.RE +.TP +.BI --cpus \ number +Specify the +.I number +of cpus in the SMP system being analyzed. +.TP +.BI --osrelease \ dumpfile +Display the OSRELEASE vmcoreinfo string from a kdump +.I dumpfile +header. +.TP +.BI --hyper +Force the session to be that of a Xen hypervisor. +.TP +.BI --p2m_mfn \ pfn +When a Xen Hypervisor or its dom0 kernel crashes, the dumpfile +is typically analyzed with either the Xen hypervisor or the dom0 kernel. +It is also possible to analyze any of the guest domU kernels if +the pfn_to_mfn_list_list +.I pfn +value of the guest kernel is passed on the +command line along with its NAMELIST and the +dumpfile. +.TP +.BI --xen_phys_start \ physical-address +Supply the base physical address of the Xen hypervisor's text and static data +for older xendump dumpfiles that did not pass that information in the dumpfile +header. +.TP +.B --zero_excluded +If a kdump dumpfile has been filtered to exclude various types of non-essential +pages, any attempt to read them will fail. With this flag, +reads from any of those pages will return zero-filled memory. +.TP +.B --no_panic +Do not attempt to find the task that was running when the kernel crashed. +Set the initial context to that of the "swapper" task on cpu 0. +.TP +.B --more +Use +.I /bin/more +as the command output scroller, overriding the default of +.I /usr/bin/less +and any settings in either +.I ./.crashrc +or +.I $HOME/.crashrc. +.TP +.B --less +Use +.I /usr/bin/less as the command output scroller, overriding +any settings in either +.I ./.crashrc +or +.I $HOME/.crashrc. +.TP +.B --hex +Set the default command output radix to 16, overriding the default radix of 10, +and any radix settings in either +.I ./.crashrc +or +.I $HOME/.crashrc. +.TP +.B --dec +Set the default command output radix to 10, overriding any +radix settings in either +.I ./.crashrc +or +.I $HOME/.crashrc. This is the default radix setting. +.TP +.B --CRASHPAGER +Use the output paging command defined in the +.B CRASHPAGER +shell environment +variable, overriding any settings in either +.I ./.crashrc +or +.I $HOME/.crashrc. +.TP +.B --no_scroll +Do not pass run-time command output to any scrolling command. +.TP +.B --no_strip +Do not strip cloned kernel text symbol names. +.TP +.B --no_crashrc +Do not execute the commands in either +.I $HOME/.crashrc +or +.I ./.crashrc. +.TP +.BI --mod \ directory +When loading the debuginfo data of kernel modules with the +.I mod -S +command, search for their object files in +.I directory +instead of in the standard location. +.TP +.BI --reloc \ size +When analyzing live x86 kernels that were configured with a +.B CONFIG_PHYSICAL_START +value that is larger than its +.B CONFIG_PHYSICAL_ALIGN +value, then it will be necessary to enter +a relocation size equal to the difference between the two values. +.TP +.B --minimal +Bring up a session that is restricted to the +.I log, dis, rd, sym, eval, set +and +.I exit +commands. This option may provide a way to +extract some minimal/quick information from a corrupted or truncated +dumpfile, or in situations where one of the several kernel subsystem +initialization routines would abort the +.B crash +session. +.TP +.BI --kvmhost \ [32|64] +When examining an x86 KVM guest dumpfile, this option specifies +that the KVM host that created the dumpfile was an x86 (32-bit) +or an x86_64 (64-bit) machine, overriding the automatically +determined value. +.TP +.BI --kvmio \ +override the automatically-calculated KVM guest I/O hole size. +.SH COMMANDS +Each +.B crash +command generally falls into one of the following categories: +.TP +.I Symbolic display +Displays of kernel text/data, which take full advantage of the power of +.B gdb +to format and display data structures symbolically. +.TP +.I System state +The majority of +.B crash +commands consist of a set of "kernel-aware" +commands, which delve into various kernel subsystems on a system-wide +or per-task basis. +.TP +.I Utility functions +A set of useful helper commands serving various purposes, some simple, +others quite powerful. +.TP +.I Session control +Commands that control the +.B crash +session itself. +.PP +The following alphabetical list consists of a very simple overview of each +.B crash +command. +However, since individual commands often have several options resulting in +significantly different output, it is suggested that the full description +of each command be viewed by executing +.I crash\ -h\ \fI\fP, +or during a +.B crash +session by simply entering +.B \fIhelp command\fP. +.TP +.I * +"pointer to" is shorthand for either the +.I struct +or +.I union +commands. It displays the contents of a kernel structure or union. +.TP +.I alias +creates a single-word alias for a command. +.TP +.I ascii +displays an ascii chart or translates a numeric value into its ascii components. +.TP +.I bt +displays a task's kernel-stack backtrace. If it is given the +.I \-a +option, it displays the stack traces of the active tasks on all CPUs. +It is often used with the +.I foreach +command to display the backtraces of all tasks with one command. +.TP +.I btop +translates a byte value (physical offset) to its page number. +.TP +.I dev +displays data concerning the character and block device +assignments, I/O port usage, I/O memory usage, and PCI device data. +.TP +.I dis +disassembles memory, either entire kernel functions, from a +location for a specified number of instructions, or from the start of a +function up to a specified memory location. +.TP +.I eval +evaluates an expression or numeric type and displays the result +in hexadecimal, decimal, octal and binary. +.TP +.I exit +causes +.B crash +to exit. +.TP +.I extend +dynamically loads or unloads +.B crash +shared object extension modules. +.TP +.I files +displays information about open files in a context. +.TP +.I foreach +repeats a specified command for the specified (or all) tasks +in the system. +.TP +.I fuser +displays the tasks using the specified file or socket. +.TP +.I gdb +passes its argument to the embedded +.B gdb +module. It is useful for executing +.B gdb +commands that have the same name as +.B crash +commands. +.TP +.I help +alone displays the command menu; if followed by a command name, a full +description of a command, its options, and examples are displayed. +Its output is far more complete and useful than this man page. +.TP +.I ipcs +displays data about the System V IPC facilities. +.TP +.I irq +displays data concerning interrupt request numbers and +bottom-half interrupt handling. +.TP +.I kmem +displays information about the use of kernel memory. +.TP +.I list +displays the contents of a linked list. +.TP +.I log +displays the kernel log_buf contents in chronological order. +.TP +.I mach +displays data specific to the machine type. +.TP +.I mod +displays information about the currently installed kernel modules, +or adds or deletes symbolic or debugging information about specified kernel +modules. +.TP +.I mount +displays information about the currently-mounted filesystems. +.TP +.I net +display various network related data. +.TP +.I p +passes its arguments to the +.B gdb +"print" command for evaluation and display. +.TP +.I ps +displays process status for specified, or all, processes +in the system. +.TP +.I pte +translates the hexadecimal contents of a PTE into its physical +page address and page bit settings. +.TP +.I ptob +translates a page frame number to its byte value. +.TP +.I ptov +translates a hexadecimal physical address into a kernel +virtual address. +.TP +.I q +is an alias for the "exit" command. +.TP +.I rd +displays the contents of memory, with the output formatted +in several different manners. +.TP +.I repeat +repeats a command indefinitely, optionally delaying a given +number of seconds between each command execution. +.TP +.I runq +displays the tasks on the run queue. +.TP +.I search +searches a range of user or kernel memory space for given value. +.TP +.I set +either sets a new context, or gets the current context for +display. +.TP +.I sig +displays signal-handling data of one or more tasks. +.TP +.I struct +displays either a structure definition or the contents of a +kernel structure at a specified address. +.TP +.I swap +displays information about each configured swap device. +.TP +.I sym +translates a symbol to its virtual address, or a static +kernel virtual address to its symbol -- or to a symbol-plus-offset value, +if appropriate. +.TP +.I sys +displays system-specific data. +.TP +.I task +displays the contents of a task_struct. +.TP +.I tree +displays the contents of a red-black tree or a radix tree. +.TP +.I timer +displays the timer queue entries, both old- and new-style, +in chronological order. +.TP +.I union +is similar to the +.I struct +command, except that it works on kernel unions. +.TP +.I vm +displays basic virtual memory information of a context. +.TP +.I vtop +translates a user or kernel virtual address to its physical +address. +.TP +.I waitq +walks the wait queue list displaying the tasks which +are blocked on the specified wait queue. +.TP +.I whatis +displays the definition of structures, unions, typedefs or +text/data symbols. +.TP +.I wr +modifies the contents of memory on a live system. +It can only be used if +.I /dev/mem +is the device file being used to access system RAM, and should obviously be used with great care. +.PP +When +.B crash +is invoked with a Xen hypervisor binary as the NAMELIST, the +command set is slightly modified. The +.I *, alias, ascii, bt, dis, eval, exit, extend, +.I gdb, help, list, log, p, pte, rd, repeat, +.I search, set, struct, sym, sys, union, +.I whatis, wr +and +.I q +commands are the same as above. The following commands +are specific to the Xen hypervisor: +.TP +.I domain +displays the contents of the domain structure for selected, or all, domains. +.TP +.I doms +displays domain status for selected, or all, domains. +.TP +.I dumpinfo +displays Xen dump information for selected, or all, cpus. +.TP +.I pcpus +displays physical cpu information for selected, or all, cpus. +.TP +.I vcpus +displays vcpu status for selected, or all, vcpus. +.SH FILES +.TP +.I .crashrc +Initialization commands. The file can be located in the user's +.B HOME +directory and/or the current directory. Commands found in the +.I .crashrc +file in the +.B HOME +directory are executed before those in the current directory's +.I .crashrc +file. +.SH ENVIRONMENT +.TP +.B EDITOR +Command input is read using +.BR readline(3). +If +.B EDITOR +is set to +.I emacs +or +.I vi +then suitable keybindings are used. If +.B EDITOR +is not set, then +.I vi +is used. This can be overridden by +.B set vi +or +.B set emacs +commands located in a +.IR .crashrc +file, or by entering +.B -e emacs +on the +.B crash +command line. +.TP +.B CRASHPAGER +If +.B CRASHPAGER +is set, its value is used as the name of the program to which command output will be sent. +If not, then command output is sent to +.B /usr/bin/less -E -X +by default. +.TP +.B CRASH_MODULE_PATH +Specifies an alternative directory tree to search for kernel module +object files. +.TP +.B CRASH_EXTENSIONS +Specifies a directory containing extension modules that will be loaded +automatically if the +.B -x +command line option is used. +.SH NOTES +.PP +If +.B crash +does not work, look for a newer version: kernel evolution frequently makes +.B crash +updates necessary. +.PP +The command +.B set scroll off +will cause output to be sent directly to +the terminal rather than through a paging program. This is useful, +for example, if you are running +.B crash +in a window of +.BR emacs . +.SH AUTHOR +Dave Anderson wrote +.B crash. +.TP +Jay Fenlason and Dave Anderson wrote this man page. +.SH "SEE ALSO" +.PP +The +.I help +command within +.B crash +provides more complete and accurate documentation than this man page. +.PP +.I http://people.redhat.com/anderson +- the home page of the +.B crash +utility. +.PP +.BR netdump (8), +.BR gdb (1) diff --git a/defs.h b/defs.h new file mode 100644 index 00000000..f45f52ae --- /dev/null +++ b/defs.h @@ -0,0 +1,5964 @@ +/* defs.h - core analysis suite + * + * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2013 David Anderson + * Copyright (C) 2002-2013 Red Hat, Inc. All rights reserved. + * Copyright (C) 2002 Silicon Graphics, Inc. + * + * 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. + */ + +#ifndef GDB_COMMON + +#include +#include +#include +#include +#include +#include +#include +#undef basename +#if !defined(__USE_GNU) +#define __USE_GNU +#include +#undef __USE_GNU +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* backtrace() */ +#include +#ifdef LZO +#include +#endif +#ifdef SNAPPY +#include +#endif + +#ifndef ATTRIBUTE_UNUSED +#define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +#endif + +#define BASELEVEL_REVISION "7.0.4" + +#undef TRUE +#undef FALSE + +#define TRUE (1) +#define FALSE (0) +#define STR(x) #x +#ifndef offsetof +# define offsetof(TYPE, MEMBER) ((ulong)&((TYPE *)0)->MEMBER) +#endif + +#if !defined(X86) && !defined(X86_64) && !defined(ALPHA) && !defined(PPC) && \ + !defined(IA64) && !defined(PPC64) && !defined(S390) && !defined(S390X) && \ + !defined(ARM) && !defined(ARM64) +#ifdef __alpha__ +#define ALPHA +#endif +#ifdef __i386__ +#define X86 +#endif +#ifdef __powerpc__ +#define PPC +#endif +#ifdef __ia64__ +#define IA64 +#endif +#ifdef __s390__ +#define S390 +#endif +#ifdef __s390x__ +#define S390X +#endif +#ifdef __powerpc64__ +#define PPC64 +#endif +#ifdef __x86_64__ +#define X86_64 +#endif +#ifdef __arm__ +#define ARM +#endif +#ifdef __aarch64__ +#define ARM64 +#endif +#endif + +#ifdef X86 +#define NR_CPUS (256) +#endif +#ifdef X86_64 +#define NR_CPUS (8192) +#endif +#ifdef ALPHA +#define NR_CPUS (64) +#endif +#ifdef PPC +#define NR_CPUS (32) +#endif +#ifdef IA64 +#define NR_CPUS (4096) +#endif +#ifdef PPC64 +#define NR_CPUS (2048) +#endif +#ifdef S390 +#define NR_CPUS (512) +#endif +#ifdef S390X +#define NR_CPUS (512) +#endif +#ifdef ARM +#define NR_CPUS (4) +#endif +#ifdef ARM64 +#define NR_CPUS (4096) /* TBD */ +#endif + +#define BUFSIZE (1500) +#define NULLCHAR ('\0') + +#define MAXARGS (100) /* max number of arguments to one function */ +#define MAXARGLEN (40) /* max length of argument */ + +#define HIST_BLKSIZE (4096) + +static inline int string_exists(char *s) { return (s ? TRUE : FALSE); } +#define STREQ(A, B) (string_exists((char *)A) && string_exists((char *)B) && \ + (strcmp((char *)(A), (char *)(B)) == 0)) +#define STRNEQ(A, B) (string_exists((char *)A) && string_exists((char *)B) && \ + (strncmp((char *)(A), (char *)(B), strlen((char *)(B))) == 0)) +#define BZERO(S, N) (memset(S, NULLCHAR, N)) +#define BCOPY(S, D, C) (memcpy(D, S, C)) +#define BNEG(S, N) (memset(S, 0xff, N)) +#define BEEP() fprintf(stderr, "%c", 0x7) +#define LASTCHAR(s) (s[strlen(s)-1]) +#define FIRSTCHAR(s) (s[0]) +#define QUOTED_STRING(s) ((FIRSTCHAR(s) == '"') && (LASTCHAR(s) == '"')) +#define SINGLE_QUOTED_STRING(s) ((FIRSTCHAR(s) == '\'') && (LASTCHAR(s) == '\'')) +#define PATHEQ(A, B) ((A) && (B) && (pathcmp((char *)(A), (char *)(B)) == 0)) + +#ifdef roundup +#undef roundup +#endif +#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) + +typedef uint64_t physaddr_t; + +#define PADDR_NOT_AVAILABLE (0x1ULL) + +typedef unsigned long long int ulonglong; +struct number_option { + ulong num; + ulonglong ll_num; + ulong retflags; +}; + +/* + * program_context flags + */ +#define LIVE_SYSTEM (0x1ULL) +#define TTY (0x2ULL) +#define RUNTIME (0x4ULL) +#define IN_FOREACH (0x8ULL) +#define MCLXCD (0x10ULL) +#define CMDLINE_IFILE (0x20ULL) +#define MFD_RDWR (0x40ULL) +#define KVMDUMP (0x80ULL) +#define SILENT (0x100ULL) +#define SADUMP (0x200ULL) +#define HASH (0x400ULL) +#define SCROLL (0x800ULL) +#define NO_CONSOLE (0x1000ULL) +#define RUNTIME_IFILE (0x2000ULL) +#define DROP_CORE (0x4000ULL) +#define LKCD (0x8000ULL) +#define GDB_INIT (0x10000ULL) +#define IN_GDB (0x20000ULL) +#define RCLOCAL_IFILE (0x40000ULL) +#define RCHOME_IFILE (0x80000ULL) +#define GET_TIMESTAMP (0x100000ULL) +#define READLINE (0x200000ULL) +#define _SIGINT_ (0x400000ULL) +#define IN_RESTART (0x800000ULL) +#define KERNEL_DEBUG_QUERY (0x1000000ULL) +#define DEVMEM (0x2000000ULL) +#define REM_LIVE_SYSTEM (0x4000000ULL) +#define NAMELIST_LOCAL (0x8000000ULL) +#define MEMSRC_LOCAL (0x10000000ULL) +#define NAMELIST_SAVED (0x20000000ULL) +#define DUMPFILE_SAVED (0x40000000ULL) +#define UNLINK_NAMELIST (0x80000000ULL) +#define NAMELIST_UNLINKED (0x100000000ULL) +#define REM_MCLXCD (0x200000000ULL) +#define REM_LKCD (0x400000000ULL) +#define NAMELIST_NO_GZIP (0x800000000ULL) +#define UNLINK_MODULES (0x1000000000ULL) +#define S390D (0x2000000000ULL) +#define REM_S390D (0x4000000000ULL) +#define SYSRQ (0x8000000000ULL) +#define KDUMP (0x10000000000ULL) +#define NETDUMP (0x20000000000ULL) +#define REM_NETDUMP (0x40000000000ULL) +#define SYSMAP (0x80000000000ULL) +#define SYSMAP_ARG (0x100000000000ULL) +#define MEMMOD (0x200000000000ULL) +#define MODPRELOAD (0x400000000000ULL) +#define DISKDUMP (0x800000000000ULL) +#define DATADEBUG (0x1000000000000ULL) +#define FINDKERNEL (0x2000000000000ULL) +#define VERSION_QUERY (0x4000000000000ULL) +#define READNOW (0x8000000000000ULL) +#define NOCRASHRC (0x10000000000000ULL) +#define INIT_IFILE (0x20000000000000ULL) +#define XENDUMP (0x40000000000000ULL) +#define XEN_HYPER (0x80000000000000ULL) +#define XEN_CORE (0x100000000000000ULL) +#define PLEASE_WAIT (0x200000000000000ULL) +#define IFILE_ERROR (0x400000000000000ULL) +#define KERNTYPES (0x800000000000000ULL) +#define MINIMAL_MODE (0x1000000000000000ULL) +#define CRASHBUILTIN (0x2000000000000000ULL) +#define PRELOAD_EXTENSIONS \ + (0x4000000000000000ULL) +#define PROC_KCORE (0x8000000000000000ULL) + +#define ACTIVE() (pc->flags & LIVE_SYSTEM) +#define DUMPFILE() (!(pc->flags & LIVE_SYSTEM)) +#define LIVE() (pc->flags2 & LIVE_DUMP || pc->flags & LIVE_SYSTEM) +#define MEMORY_SOURCES (NETDUMP|KDUMP|MCLXCD|LKCD|DEVMEM|S390D|MEMMOD|DISKDUMP|XENDUMP|CRASHBUILTIN|KVMDUMP|PROC_KCORE|SADUMP) +#define DUMPFILE_TYPES (DISKDUMP|NETDUMP|KDUMP|MCLXCD|LKCD|S390D|XENDUMP|KVMDUMP|SADUMP) +#define REMOTE() (pc->flags2 & REMOTE_DAEMON) +#define REMOTE_ACTIVE() (pc->flags & REM_LIVE_SYSTEM) +#define REMOTE_DUMPFILE() \ + (pc->flags & (REM_NETDUMP|REM_MCLXCD|REM_LKCD|REM_S390D)) +#define REMOTE_MEMSRC() (REMOTE_ACTIVE() || REMOTE_PAUSED() || REMOTE_DUMPFILE()) +#define LKCD_DUMPFILE() (pc->flags & (LKCD|REM_LKCD)) +#define NETDUMP_DUMPFILE() (pc->flags & (NETDUMP|REM_NETDUMP)) +#define DISKDUMP_DUMPFILE() (pc->flags & DISKDUMP) +#define KDUMP_DUMPFILE() (pc->flags & KDUMP) +#define XENDUMP_DUMPFILE() (pc->flags & XENDUMP) +#define XEN_HYPER_MODE() (pc->flags & XEN_HYPER) +#define SYSRQ_TASK(X) ((pc->flags & SYSRQ) && is_task_active(X)) +#define XEN_CORE_DUMPFILE() (pc->flags & XEN_CORE) +#define LKCD_KERNTYPES() (pc->flags & KERNTYPES) +#define KVMDUMP_DUMPFILE() (pc->flags & KVMDUMP) +#define SADUMP_DUMPFILE() (pc->flags & SADUMP) + +#define NETDUMP_LOCAL (0x1) /* netdump_data flags */ +#define NETDUMP_REMOTE (0x2) +#define VMCORE_VALID() (nd->flags & (NETDUMP_LOCAL|NETDUMP_REMOTE|KDUMP_LOCAL)) +#define NETDUMP_ELF32 (0x4) +#define NETDUMP_ELF64 (0x8) +#define PARTIAL_DUMP (0x10) /* netdump or diskdump */ +#define KDUMP_ELF32 (0x20) +#define KDUMP_ELF64 (0x40) +#define KDUMP_LOCAL (0x80) +#define KCORE_LOCAL (0x100) +#define KCORE_ELF32 (0x200) +#define KCORE_ELF64 (0x400) +#define QEMU_MEM_DUMP_KDUMP_BACKUP \ + (0x800) +#define KVMDUMP_LOCAL (0x1) +#define KVMDUMP_VALID() (kvm->flags & (KVMDUMP_LOCAL)) + +#define DUMPFILE_FORMAT(flags) ((flags) & \ + (NETDUMP_ELF32|NETDUMP_ELF64|KDUMP_ELF32|KDUMP_ELF64)) + +#define DISKDUMP_LOCAL (0x1) +#define KDUMP_CMPRS_LOCAL (0x2) +#define ERROR_EXCLUDED (0x4) +#define ZERO_EXCLUDED (0x8) +#define DUMPFILE_SPLIT (0x10) +#define NO_ELF_NOTES (0x20) +#define LZO_SUPPORTED (0x40) +#define SNAPPY_SUPPORTED (0x80) +#define DISKDUMP_VALID() (dd->flags & DISKDUMP_LOCAL) +#define KDUMP_CMPRS_VALID() (dd->flags & KDUMP_CMPRS_LOCAL) +#define KDUMP_SPLIT() (dd->flags & DUMPFILE_SPLIT) + +#define XENDUMP_LOCAL (0x1) +#define XENDUMP_VALID() (xd->flags & XENDUMP_LOCAL) + +#define SADUMP_LOCAL (0x1) +#define SADUMP_DISKSET (0x2) +#define SADUMP_MEDIA (0x4) +#define SADUMP_ZERO_EXCLUDED (0x8) +#define SADUMP_KDUMP_BACKUP (0x10) +#define SADUMP_VALID() (sd->flags & SADUMP_LOCAL) + +#define CRASHDEBUG(x) (pc->debug >= (x)) + +#define CRASHDEBUG_SUSPEND(X) { pc->debug_save = pc->debug; pc->debug = X; } +#define CRASHDEBUG_RESTORE() { pc->debug = pc->debug_save; } + +#define VERBOSE (0x1) +#define ADDRESS_SPECIFIED (0x2) + +#define FAULT_ON_ERROR (0x1) +#define RETURN_ON_ERROR (0x2) +#define QUIET (0x4) +#define HEX_BIAS (0x8) +#define LONG_LONG (0x10) +#define RETURN_PARTIAL (0x20) + +#define SEEK_ERROR (-1) +#define READ_ERROR (-2) +#define WRITE_ERROR (-3) +#define PAGE_EXCLUDED (-4) + +#define RESTART() (longjmp(pc->main_loop_env, 1)) +#define RESUME_FOREACH() (longjmp(pc->foreach_loop_env, 1)) + +#define INFO (1) +#define FATAL (2) +#define FATAL_RESTART (3) +#define WARNING (4) +#define NOTE (5) +#define CONT (6) +#define FATAL_ERROR(x) (((x) == FATAL) || ((x) == FATAL_RESTART)) + +#define CONSOLE_OFF(x) ((x) = console_off()) +#define CONSOLE_ON(x) (console_on(x)) + +#define RADIX(X) (X) + +#define NUM_HEX (0x1) +#define NUM_DEC (0x2) +#define NUM_EXPR (0x4) +#define NUM_ANY (NUM_HEX|NUM_DEC|NUM_EXPR) + +/* + * program context redirect flags + */ +#define FROM_COMMAND_LINE (0x1) +#define FROM_INPUT_FILE (0x2) +#define REDIRECT_NOT_DONE (0x4) +#define REDIRECT_TO_PIPE (0x8) +#define REDIRECT_TO_STDPIPE (0x10) +#define REDIRECT_TO_FILE (0x20) +#define REDIRECT_FAILURE (0x40) +#define REDIRECT_SHELL_ESCAPE (0x80) +#define REDIRECT_SHELL_COMMAND (0x100) +#define REDIRECT_PID_KNOWN (0x200) +#define REDIRECT_MULTI_PIPE (0x400) + +#define PIPE_OPTIONS (FROM_COMMAND_LINE | FROM_INPUT_FILE | REDIRECT_TO_PIPE | \ + REDIRECT_TO_STDPIPE | REDIRECT_TO_FILE) + +#define DEFAULT_REDHAT_DEBUG_LOCATION "/usr/lib/debug/lib/modules" + +#define MEMORY_DRIVER_MODULE "crash" +#define MEMORY_DRIVER_DEVICE "/dev/crash" +#define MEMORY_DRIVER_DEVICE_MODE (S_IFCHR|S_IRUSR) + +/* + * structure definitions + */ +struct program_context { + char *program_name; /* this program's name */ + char *program_path; /* unadulterated argv[0] */ + char *program_version; /* this program's version */ + char *gdb_version; /* embedded gdb version */ + char *prompt; /* this program's prompt */ + unsigned long long flags; /* flags from above */ + char *namelist; /* linux namelist */ + char *dumpfile; /* dumpfile or /dev/kmem */ + char *live_memsrc; /* live memory driver */ + char *system_map; /* get symbol values from System.map */ + char *namelist_debug; /* namelist containing debug data */ + char *debuginfo_file; /* separate debuginfo file */ + char *memory_module; /* alternative to mem.c driver */ + char *memory_device; /* alternative to /dev/[k]mem device */ + char *machine_type; /* machine's processor type */ + char *editing_mode; /* readline vi or emacs */ + char *server; /* network daemon */ + char *server_memsrc; /* memory source on server */ + char *server_namelist; /* kernel namelist on server */ + int nfd; /* linux namelist fd */ + int mfd; /* /dev/mem fd */ + int kfd; /* /dev/kmem fd */ + int dfd; /* dumpfile fd */ + int confd; /* console fd */ + int sockfd; /* network daemon socket */ + ushort port; /* network daemon port */ + int rmfd; /* remote server memory source fd */ + int rkfd; /* remote server /dev/kmem fd */ + ulong program_pid; /* program pid */ + ulong server_pid; /* server pid */ + ulong rcvbufsize; /* client-side receive buffer size */ + char *home; /* user's home directory */ + char command_line[BUFSIZE]; /* possibly parsed input command line */ + char orig_line[BUFSIZE]; /* original input line */ + char *readline; /* pointer to last readline() return */ + char my_tty[10]; /* real tty name (shown by ps -ef) */ + ulong debug; /* level of debug */ + ulong debug_save; /* saved level for debug-suspend */ + char *console; /* current debug console device */ + char *redhat_debug_loc; /* location of matching debug objects */ + int pipefd[2]; /* output pipe file descriptors */ + FILE *nullfp; /* bitbucket */ + FILE *stdpipe; /* standard pipe for output */ + FILE *pipe; /* command line specified pipe */ + FILE *ofile; /* command line specified output file */ + FILE *ifile; /* command line specified input file */ + FILE *ifile_pipe; /* output pipe specified from file */ + FILE *ifile_ofile; /* output file specified from file */ + FILE *symfile; /* symbol table data file */ + FILE *symfile2; /* alternate access to above */ + FILE *tmpfile; /* tmpfile for selective data output */ + FILE *saved_fp; /* for printing while parsing tmpfile */ + FILE *tmp_fp; /* stored tmpfile pointer */ + char *input_file; /* input file specified at invocation */ + FILE *tmpfile2; /* tmpfile2 does not use save_fp! */ + int eoc_index; /* end of redirected command index */ + int scroll_command; /* default scroll command for output */ +#define SCROLL_NONE 0 +#define SCROLL_LESS 1 +#define SCROLL_MORE 2 +#define SCROLL_CRASHPAGER 3 + ulong redirect; /* per-cmd origin and output flags */ + pid_t stdpipe_pid; /* per-cmd standard output pipe's pid */ + pid_t pipe_pid; /* per-cmd output pipe's pid */ + pid_t pipe_shell_pid; /* per-cmd output pipe's shell pid */ + char pipe_command[BUFSIZE]; /* pipe command line */ + struct command_table_entry *cmd_table; /* linux/xen command table */ + char *curcmd; /* currently-executing command */ + char *lastcmd; /* previously-executed command */ + ulong cmdgencur; /* current command generation number */ + ulong curcmd_flags; /* general purpose per-command flag */ +#define XEN_MACHINE_ADDR (0x1) +#define REPEAT (0x2) +#define IDLE_TASK_SHOWN (0x4) +#define TASK_SPECIFIED (0x8) +#define MEMTYPE_UVADDR (0x10) +#define MEMTYPE_FILEADDR (0x20) +#define HEADER_PRINTED (0x40) +#define BAD_INSTRUCTION (0x80) +#define UD2A_INSTRUCTION (0x100) +#define IRQ_IN_USE (0x200) +#define NO_MODIFY (0x400) +#define IGNORE_ERRORS (0x800) +#define FROM_RCFILE (0x1000) +#define MEMTYPE_KVADDR (0x2000) +#define MOD_SECTIONS (0x4000) +#define MOD_READNOW (0x8000) + ulonglong curcmd_private; /* general purpose per-command info */ + int cur_gdb_cmd; /* current gdb command */ + int last_gdb_cmd; /* previously-executed gdb command */ + int sigint_cnt; /* number of ignored SIGINTs */ + struct gnu_request *cur_req; /* current gdb gnu_request */ + struct sigaction sigaction; /* general usage sigaction. */ + struct sigaction gdb_sigaction; /* gdb's SIGINT sigaction. */ + jmp_buf main_loop_env; /* longjmp target default */ + jmp_buf foreach_loop_env; /* longjmp target within foreach */ + jmp_buf gdb_interface_env; /* longjmp target for gdb error catch */ + struct termios termios_orig; /* non-raw settings */ + struct termios termios_raw; /* while gathering command input */ + int ncmds; /* number of commands in menu */ + char **cmdlist; /* current list of available commands */ + int cmdlistsz; /* space available in cmdlist */ + unsigned output_radix; /* current gdb output_radix */ + void *sbrk; /* current sbrk value */ + struct extension_table *curext; /* extension being loaded */ + int (*readmem)(int, void *, int, ulong, physaddr_t); /* memory access */ + int (*writemem)(int, void *, int, ulong, physaddr_t);/* memory access */ + ulong ifile_in_progress; /* original xxx_IFILE flags */ + off_t ifile_offset; /* current offset into input file */ + char *runtime_ifile_cmd; /* runtime command using input file */ + char *kvmdump_mapfile; /* storage of physical to file offsets */ + ulonglong flags2; /* flags overrun */ +#define FLAT (0x01ULL) +#define ELF_NOTES (0x02ULL) +#define GET_OSRELEASE (0x04ULL) +#define REMOTE_DAEMON (0x08ULL) +#define ERASEINFO_DATA (0x10ULL) +#define GDB_CMD_MODE (0x20ULL) +#define LIVE_DUMP (0x40ULL) +#define FLAT_FORMAT() (pc->flags2 & FLAT) +#define ELF_NOTES_VALID() (pc->flags2 & ELF_NOTES) +#define RADIX_OVERRIDE (0x80ULL) +#define QEMU_MEM_DUMP (0x100ULL) +#define GET_LOG (0x200ULL) +#define VMCOREINFO (0x400ULL) +#define ALLOW_FP (0x800ULL) +#define REM_PAUSED_F (0x1000ULL) +#define REMOTE_PAUSED() (pc->flags2 & REM_PAUSED_F) + char *cleanup; + char *namelist_orig; + char *namelist_debug_orig; + FILE *args_ifile; /* per-command args input file */ + void (*cmd_cleanup)(void *); /* per-command cleanup function */ + void *cmd_cleanup_arg; /* optional cleanup function argument */ + ulong scope; /* optional text context address */ +}; + +#define READMEM pc->readmem + +typedef void (*cmd_func_t)(void); + +struct command_table_entry { /* one for each command in menu */ + char *name; + cmd_func_t func; + char **help_data; + ulong flags; +}; + +struct args_input_file { + int index; + int args_used; + int is_gdb_cmd; + int in_expression; + int start; + int resume; + char *fileptr; +}; + +#define REFRESH_TASK_TABLE (0x1) /* command_table_entry flags */ +#define HIDDEN_COMMAND (0x2) +#define CLEANUP (0x4) /* for extensions only */ +#define MINIMAL (0x8) + +/* + * A linked list of extension table structures keeps track of the current + * set of shared library extensions. + */ +struct extension_table { + void *handle; /* handle from dlopen() */ + char *filename; /* name of shared library */ + struct command_table_entry *command_table; /* list of commands */ + ulong flags; /* registration flags */ + struct extension_table *next, *prev; /* bookkeeping */ +}; + +#define REGISTERED (0x1) /* extension_table flags */ +#define DUPLICATE_COMMAND_NAME (0x2) +#define NO_MINIMAL_COMMANDS (0x4) + +struct new_utsname { + char sysname[65]; + char nodename[65]; + char release[65]; + char version[65]; + char machine[65]; + char domainname[65]; +}; + +#define NO_MODULE_ACCESS (0x1) +#define TVEC_BASES_V1 (0x2) +#define GCC_3_2 (0x4) +#define GCC_3_2_3 (0x8) +#define GCC_2_96 (0x10) +#define RA_SEEK (0x20) +#define NO_RA_SEEK (0x40) +#define KALLSYMS_V1 (0x80) +#define NO_KALLSYMS (0x100) +#define PER_CPU_OFF (0x200) +#define SMP (0x400) +#define GCC_3_3_2 (0x800) +#define KMOD_V1 (0x1000) +#define KMOD_V2 (0x2000) +#define KALLSYMS_V2 (0x2000) +#define TVEC_BASES_V2 (0x4000) +#define GCC_3_3_3 (0x8000) +#define USE_OLD_BT (0x10000) +#define ARCH_XEN (0x20000) +#define NO_IKCONFIG (0x40000) +#define DWARF_UNWIND (0x80000) +#define NO_DWARF_UNWIND (0x100000) +#define DWARF_UNWIND_MEMORY (0x200000) +#define DWARF_UNWIND_EH_FRAME (0x400000) +#define DWARF_UNWIND_CAPABLE (DWARF_UNWIND_MEMORY|DWARF_UNWIND_EH_FRAME) +#define DWARF_UNWIND_MODULES (0x800000) +#define BUGVERBOSE_OFF (0x1000000) +#define RELOC_SET (0x2000000) +#define RELOC_FORCE (0x4000000) +#define ARCH_OPENVZ (0x8000000) +#define ARCH_PVOPS (0x10000000) +#define PRE_KERNEL_INIT (0x20000000) +#define ARCH_PVOPS_XEN (0x40000000) +#define IRQ_DESC_TREE (0x80000000) + +#define GCC_VERSION_DEPRECATED (GCC_3_2|GCC_3_2_3|GCC_2_96|GCC_3_3_2|GCC_3_3_3) + +#define XEN() (kt->flags & ARCH_XEN) +#define OPENVZ() (kt->flags & ARCH_OPENVZ) +#define PVOPS() (kt->flags & ARCH_PVOPS) +#define PVOPS_XEN() (kt->flags & ARCH_PVOPS_XEN) + +#define XEN_MACHINE_TO_MFN(m) ((ulonglong)(m) >> PAGESHIFT()) +#define XEN_PFN_TO_PSEUDO(p) ((ulonglong)(p) << PAGESHIFT()) + +#define XEN_MFN_NOT_FOUND (~0UL) +#define XEN_PFNS_PER_PAGE (PAGESIZE()/sizeof(ulong)) +#define XEN_FOREIGN_FRAME (1UL << (BITS()-1)) + +#define XEN_MACHADDR_NOT_FOUND (~0ULL) + +#define XEN_P2M_PER_PAGE (PAGESIZE() / sizeof(unsigned long)) +#define XEN_P2M_MID_PER_PAGE (PAGESIZE() / sizeof(unsigned long *)) +#define XEN_P2M_TOP_PER_PAGE (PAGESIZE() / sizeof(unsigned long **)) + +struct kernel_table { /* kernel data */ + ulong flags; + ulong stext; + ulong etext; + ulong stext_init; + ulong etext_init; + ulong init_begin; + ulong init_end; + ulong end; + int cpus; + char *cpus_override; + void (*display_bh)(void); + ulong module_list; + ulong kernel_module; + int mods_installed; + struct timespec date; + char proc_version[BUFSIZE]; + struct new_utsname utsname; + uint kernel_version[3]; + uint gcc_version[3]; + int runq_siblings; + int kernel_NR_CPUS; + long __per_cpu_offset[NR_CPUS]; + long *__rq_idx; + long *__cpu_idx; + ulong *cpu_flags; +#define POSSIBLE (0x1) +#define PRESENT (0x2) +#define ONLINE (0x4) +#define NMI (0x8) + int BUG_bytes; + ulong xen_flags; +#define WRITABLE_PAGE_TABLES (0x1) +#define SHADOW_PAGE_TABLES (0x2) +#define CANONICAL_PAGE_TABLES (0x4) +#define XEN_SUSPEND (0x8) + char *m2p_page; + ulong phys_to_machine_mapping; + ulong p2m_table_size; +#define P2M_MAPPING_CACHE (512) + struct p2m_mapping_cache { + ulong mapping; + ulong pfn; + ulong start; + ulong end; + } p2m_mapping_cache[P2M_MAPPING_CACHE]; +#define P2M_MAPPING_PAGE_PFN(c) \ + (PVOPS_XEN() ? kt->p2m_mapping_cache[c].pfn : \ + (((kt->p2m_mapping_cache[c].mapping - kt->phys_to_machine_mapping)/PAGESIZE()) \ + * XEN_PFNS_PER_PAGE)) + ulong last_mapping_read; + ulong p2m_cache_index; + ulong p2m_pages_searched; + ulong p2m_mfn_cache_hits; + ulong p2m_page_cache_hits; + ulong relocate; + char *module_tree; + struct pvops_xen_info { + int p2m_top_entries; + ulong p2m_top; + ulong p2m_mid_missing; + ulong p2m_missing; + } pvops_xen; + int highest_irq; +#define IKCONFIG_AVAIL 0x1 /* kernel contains ikconfig data */ +#define IKCONFIG_LOADED 0x2 /* ikconfig data is currently loaded */ + int ikconfig_flags; + int ikconfig_ents; + char *hypervisor; + struct vmcoreinfo_data { + ulong log_buf_SYMBOL; + ulong log_end_SYMBOL; + ulong log_buf_len_SYMBOL; + ulong logged_chars_SYMBOL; + ulong log_first_idx_SYMBOL; + ulong log_next_idx_SYMBOL; + long log_SIZE; + long log_ts_nsec_OFFSET; + long log_len_OFFSET; + long log_text_len_OFFSET; + long log_dict_len_OFFSET; + ulong phys_base_SYMBOL; + ulong _stext_SYMBOL; + } vmcoreinfo; +}; + +/* + * Aid for the two versions of the kernel's module list linkage. + */ +#define NEXT_MODULE(next_module, modbuf) \ +{ \ + switch (kt->flags & (KMOD_V1|KMOD_V2)) \ + { \ + case KMOD_V1: \ + next_module = ULONG(modbuf + OFFSET(module_next)); \ + break; \ + case KMOD_V2: \ + next_module = ULONG(modbuf + OFFSET(module_list)); \ + if (next_module != kt->kernel_module) \ + next_module -= OFFSET(module_list); \ + break; \ + } \ +} + +#define THIS_KERNEL_VERSION ((kt->kernel_version[0] << 16) + \ + (kt->kernel_version[1] << 8) + \ + (kt->kernel_version[2])) +#define LINUX(x,y,z) (((uint)(x) << 16) + ((uint)(y) << 8) + (uint)(z)) + +#define THIS_GCC_VERSION ((kt->gcc_version[0] << 16) + \ + (kt->gcc_version[1] << 8) + \ + (kt->gcc_version[2])) +#define GCC(x,y,z) (((uint)(x) << 16) + ((uint)(y) << 8) + (uint)(z)) + +#define IS_KERNEL_STATIC_TEXT(x) (((ulong)(x) >= kt->stext) && \ + ((ulong)(x) < kt->etext)) + +#define TASK_COMM_LEN 16 /* task command name length including NULL */ + +struct task_context { /* context stored for each task */ + ulong task; + ulong thread_info; + ulong pid; + char comm[TASK_COMM_LEN+1]; + int processor; + ulong ptask; + ulong mm_struct; + struct task_context *tc_next; +}; + +struct task_table { /* kernel/local task table data */ + struct task_context *current; + struct task_context *context_array; + void (*refresh_task_table)(void); + ulong flags; + ulong task_start; + ulong task_end; + void *task_local; + int max_tasks; + int nr_threads; + ulong running_tasks; + ulong retries; + ulong panicmsg; + int panic_processor; + ulong *idle_threads; + ulong *panic_threads; + ulong *active_set; + ulong *panic_ksp; + ulong *hardirq_ctx; + ulong *hardirq_tasks; + ulong *softirq_ctx; + ulong *softirq_tasks; + ulong panic_task; + ulong this_task; + int pidhash_len; + ulong pidhash_addr; + ulong last_task_read; + ulong last_thread_info_read; + ulong last_mm_read; + char *task_struct; + char *thread_info; + char *mm_struct; + ulong init_pid_ns; +}; + +#define TASK_INIT_DONE (0x1) +#define TASK_ARRAY_EXISTS (0x2) +#define PANIC_TASK_NOT_FOUND (0x4) +#define TASK_REFRESH (0x8) +#define TASK_REFRESH_OFF (0x10) +#define PANIC_KSP (0x20) +#define ACTIVE_SET (0x40) +#define POPULATE_PANIC (0x80) +#define PIDHASH (0x100) +#define PID_HASH (0x200) +#define THREAD_INFO (0x400) +#define IRQSTACKS (0x800) +#define TIMESPEC (0x1000) +#define NO_TIMESPEC (0x2000) +#define ACTIVE_ONLY (0x4000) + +#define TASK_SLUSH (20) + +#define NO_PROC_ID 0xFF /* No processor magic marker (from kernel) */ + +/* + * Global "tt" points to task_table + */ +#define CURRENT_CONTEXT() (tt->current) +#define CURRENT_TASK() (tt->current->task) +#define CURRENT_PID() (tt->current->pid) +#define CURRENT_COMM() (tt->current->comm) +#define RUNNING_TASKS() (tt->running_tasks) +#define FIRST_CONTEXT() (tt->context_array) + +#define NO_PID ((ulong)-1) +#define NO_TASK (0) + +#define IS_TASK_ADDR(X) (machdep->is_task_addr(X)) +#define GET_STACKBASE(X) (machdep->get_stackbase(X)) +#define GET_STACKTOP(X) (machdep->get_stacktop(X)) +#define STACKSIZE() (machdep->stacksize) +#define LONGS_PER_STACK (machdep->stacksize/sizeof(ulong)) + +#define INSTACK(X,BT) \ + (((ulong)(X) >= (BT)->stackbase) && ((ulong)(X) < (BT)->stacktop)) + +#define ALIGNED_STACK_OFFSET(task) ((ulong)(task) & (STACKSIZE()-1)) + +#define BITS() (machdep->bits) +#define BITS32() (machdep->bits == 32) +#define BITS64() (machdep->bits == 64) +#define IS_KVADDR(X) (machdep->is_kvaddr(X)) +#define IS_UVADDR(X,C) (machdep->is_uvaddr(X,C)) + +#define PID_ALIVE(x) (kill(x, 0) == 0) + +struct kernel_list_head { + struct kernel_list_head *next, *prev; +}; + +struct stack_hook { + ulong esp; + ulong eip; +}; + +struct bt_info { + ulong task; + ulonglong flags; + ulong instptr; + ulong stkptr; + ulong bptr; + ulong stackbase; + ulong stacktop; + char *stackbuf; + struct task_context *tc; + struct stack_hook *hp; + struct stack_hook *textlist; + struct reference *ref; + ulong frameptr; + char *call_target; + void *machdep; + ulong debug; + ulong eframe_ip; + ulong radix; +}; + +#define STACK_OFFSET_TYPE(OFF) \ + (((ulong)(OFF) > STACKSIZE()) ? \ + (ulong)((ulong)(OFF) - (ulong)(bt->stackbase)) : (ulong)(OFF)) + +#define GET_STACK_ULONG(OFF) \ + *((ulong *)((char *)(&bt->stackbuf[(ulong)(STACK_OFFSET_TYPE(OFF))]))) + +#define GET_STACK_DATA(OFF, LOC, SZ) memcpy((void *)(LOC), \ + (void *)(&bt->stackbuf[(ulong)STACK_OFFSET_TYPE(OFF)]), (size_t)(SZ)) + +struct machine_specific; /* uniquely defined below each machine's area */ +struct xendump_data; +struct xen_kdump_data; + +struct vaddr_range { + ulong start; + ulong end; + ulong type; +#define KVADDR_UNITY_MAP (1) +#define KVADDR_VMALLOC (2) +#define KVADDR_VMEMMAP (3) +#define KVADDR_START_MAP (4) +#define KVADDR_MODULES (5) +#define MAX_KVADDR_RANGES KVADDR_MODULES +}; + +#define MAX_MACHDEP_ARGS 5 /* for --machdep/-m machine-specific args */ + +struct machdep_table { + ulong flags; + ulong kvbase; + ulong identity_map_base; + uint pagesize; + uint pageshift; + ulonglong pagemask; + ulong pageoffset; + ulong stacksize; + uint hz; + ulong mhz; + int bits; + int nr_irqs; + uint64_t memsize; + int (*eframe_search)(struct bt_info *); + void (*back_trace)(struct bt_info *); + ulong (*processor_speed)(void); + int (*uvtop)(struct task_context *, ulong, physaddr_t *, int); + int (*kvtop)(struct task_context *, ulong, physaddr_t *, int); + ulong (*get_task_pgd)(ulong); + void (*dump_irq)(int); + void (*get_stack_frame)(struct bt_info *, ulong *, ulong *); + ulong (*get_stackbase)(ulong); + ulong (*get_stacktop)(ulong); + int (*translate_pte)(ulong, void *, ulonglong); + uint64_t (*memory_size)(void); + ulong (*vmalloc_start)(void); + int (*is_task_addr)(ulong); + int (*verify_symbol)(const char *, ulong, char); + int (*dis_filter)(ulong, char *, unsigned int); + int (*get_smp_cpus)(void); + int (*is_kvaddr)(ulong); + int (*is_uvaddr)(ulong, struct task_context *); + int (*verify_paddr)(uint64_t); + void (*cmd_mach)(void); + void (*init_kernel_pgd)(void); + struct syment *(*value_to_symbol)(ulong, ulong *); + struct line_number_hook { + char *func; + char **file; + } *line_number_hooks; + ulong last_pgd_read; + ulong last_pud_read; + ulong last_pmd_read; + ulong last_ptbl_read; + char *pgd; + char *pud; + char *pmd; + char *ptbl; + int ptrs_per_pgd; + char *cmdline_args[MAX_MACHDEP_ARGS]; + struct machine_specific *machspec; + ulong section_size_bits; + ulong max_physmem_bits; + ulong sections_per_root; + int (*xendump_p2m_create)(struct xendump_data *); + ulong (*xendump_panic_task)(struct xendump_data *); + void (*get_xendump_regs)(struct xendump_data *, struct bt_info *, ulong *, ulong *); + void (*clear_machdep_cache)(void); + int (*xen_kdump_p2m_create)(struct xen_kdump_data *); + int (*in_alternate_stack)(int, ulong); + void (*dumpfile_init)(int, void *); + void (*process_elf_notes)(void *, unsigned long); + int (*get_kvaddr_ranges)(struct vaddr_range *); + int (*verify_line_number)(ulong, ulong, ulong); + void (*get_irq_affinity)(int); + void (*show_interrupts)(int, ulong *); +}; + +/* + * Processor-common flags; processor-specific flags use the lower bits + * as defined in their processor-specific files below. (see KSYMS_START defs). + */ +#define HWRESET (0x80000000) +#define OMIT_FRAME_PTR (0x40000000) +#define FRAMESIZE_DEBUG (0x20000000) +#define MACHDEP_BT_TEXT (0x10000000) +#define DEVMEMRD (0x8000000) +#define INIT (0x4000000) +#define VM_4_LEVEL (0x2000000) +#define MCA (0x1000000) +#define PAE (0x800000) +#define VMEMMAP (0x400000) + +extern struct machdep_table *machdep; + +#ifndef HZ +#define HZ sysconf(_SC_CLK_TCK) +#endif + +#define IS_LAST_PGD_READ(pgd) ((ulong)(pgd) == machdep->last_pgd_read) +#define IS_LAST_PMD_READ(pmd) ((ulong)(pmd) == machdep->last_pmd_read) +#define IS_LAST_PTBL_READ(ptbl) ((ulong)(ptbl) == machdep->last_ptbl_read) +#define IS_LAST_PUD_READ(pud) ((ulong)(pud) == machdep->last_pud_read) + +#define FILL_PGD(PGD, TYPE, SIZE) \ + if (!IS_LAST_PGD_READ(PGD)) { \ + readmem((ulonglong)((ulong)(PGD)), TYPE, machdep->pgd, \ + SIZE, "pgd page", FAULT_ON_ERROR); \ + machdep->last_pgd_read = (ulong)(PGD); \ + } + +#define FILL_PUD(PUD, TYPE, SIZE) \ + if (!IS_LAST_PUD_READ(PUD)) { \ + readmem((ulonglong)((ulong)(PUD)), TYPE, machdep->pud, \ + SIZE, "pud page", FAULT_ON_ERROR); \ + machdep->last_pud_read = (ulong)(PUD); \ + } + +#define FILL_PMD(PMD, TYPE, SIZE) \ + if (!IS_LAST_PMD_READ(PMD)) { \ + readmem((ulonglong)(PMD), TYPE, machdep->pmd, \ + SIZE, "pmd page", FAULT_ON_ERROR); \ + machdep->last_pmd_read = (ulong)(PMD); \ + } + +#define FILL_PTBL(PTBL, TYPE, SIZE) \ + if (!IS_LAST_PTBL_READ(PTBL)) { \ + readmem((ulonglong)(PTBL), TYPE, machdep->ptbl, \ + SIZE, "page table", FAULT_ON_ERROR); \ + machdep->last_ptbl_read = (ulong)(PTBL); \ + } + +#define SETUP_ENV (0) +#define PRE_SYMTAB (1) +#define PRE_GDB (2) +#define POST_GDB (3) +#define POST_INIT (4) +#define POST_VM (5) +#define LOG_ONLY (6) + +#define FOREACH_BT (1) +#define FOREACH_VM (2) +#define FOREACH_TASK (3) +#define FOREACH_SET (4) +#define FOREACH_FILES (5) +#define FOREACH_NET (6) +#define FOREACH_TEST (7) +#define FOREACH_VTOP (8) +#define FOREACH_SIG (9) +#define FOREACH_PS (10) + +#define MAX_FOREACH_KEYWORDS (10) +#define MAX_FOREACH_TASKS (50) +#define MAX_FOREACH_PIDS (50) +#define MAX_FOREACH_COMMS (50) +#define MAX_FOREACH_ARGS (50) +#define MAX_REGEX_ARGS (10) + +#define FOREACH_CMD (0x1) +#define FOREACH_r_FLAG (0x2) +#define FOREACH_s_FLAG (0x4) +#define FOREACH_S_FLAG (0x8) +#define FOREACH_i_FLAG (0x10) +#define FOREACH_e_FLAG (0x20) +#define FOREACH_g_FLAG (0x40) +#define FOREACH_l_FLAG (0x80) +#define FOREACH_p_FLAG (0x100) +#define FOREACH_t_FLAG (0x200) +#define FOREACH_u_FLAG (0x400) +#define FOREACH_m_FLAG (0x800) +#define FOREACH_v_FLAG (0x1000) +#define FOREACH_KERNEL (0x2000) +#define FOREACH_USER (0x4000) +#define FOREACH_SPECIFIED (0x8000) +#define FOREACH_ACTIVE (0x10000) +#define FOREACH_k_FLAG (0x20000) +#define FOREACH_c_FLAG (0x40000) +#define FOREACH_f_FLAG (0x80000) +#define FOREACH_o_FLAG (0x100000) +#define FOREACH_T_FLAG (0x200000) +#define FOREACH_F_FLAG (0x400000) +#define FOREACH_x_FLAG (0x800000) +#define FOREACH_d_FLAG (0x1000000) +#define FOREACH_STATE (0x2000000) +#define FOREACH_a_FLAG (0x4000000) +#define FOREACH_G_FLAG (0x8000000) + +#define FOREACH_PS_EXCLUSIVE \ + (FOREACH_g_FLAG|FOREACH_a_FLAG|FOREACH_t_FLAG|FOREACH_c_FLAG|FOREACH_p_FLAG|FOREACH_l_FLAG|FOREACH_r_FLAG) + +struct foreach_data { + ulong flags; + int keyword_array[MAX_FOREACH_KEYWORDS]; + ulong task_array[MAX_FOREACH_TASKS]; + char *comm_array[MAX_FOREACH_COMMS]; + ulong pid_array[MAX_FOREACH_PIDS]; + ulong arg_array[MAX_FOREACH_ARGS]; + struct regex_info { + char *pattern; + regex_t regex; + } regex_info[MAX_REGEX_ARGS]; + ulong state; + char *reference; + int keys; + int pids; + int tasks; + int comms; + int args; + int regexs; +}; + +struct reference { + char *str; + ulong cmdflags; + ulong hexval; + ulong decval; + ulong ref1; + ulong ref2; + void *refp; +}; + +struct offset_table { /* stash of commonly-used offsets */ + long list_head_next; /* add new entries to end of table */ + long list_head_prev; + long task_struct_pid; + long task_struct_state; + long task_struct_comm; + long task_struct_mm; + long task_struct_tss; + long task_struct_thread; + long task_struct_active_mm; + long task_struct_tss_eip; + long task_struct_tss_esp; + long task_struct_tss_ksp; + long task_struct_processor; + long task_struct_p_pptr; + long task_struct_parent; + long task_struct_has_cpu; + long task_struct_cpus_runnable; + long task_struct_thread_eip; + long task_struct_thread_esp; + long task_struct_thread_ksp; + long task_struct_next_task; + long task_struct_files; + long task_struct_fs; + long task_struct_pidhash_next; + long task_struct_next_run; + long task_struct_flags; + long task_struct_sig; + long task_struct_signal; + long task_struct_blocked; + long task_struct_sigpending; + long task_struct_pending; + long task_struct_sigqueue; + long task_struct_sighand; + long task_struct_start_time; + long task_struct_times; + long task_struct_utime; + long task_struct_stime; + long task_struct_cpu; + long task_struct_run_list; + long task_struct_pgrp; + long task_struct_tgid; + long task_struct_namespace; + long task_struct_pids; + long task_struct_last_run; + long task_struct_timestamp; + long task_struct_thread_info; + long task_struct_nsproxy; + long task_struct_rlim; + long thread_info_task; + long thread_info_cpu; + long thread_info_previous_esp; + long thread_info_flags; + long nsproxy_mnt_ns; + long mnt_namespace_root; + long mnt_namespace_list; + long pid_link_pid; + long pid_hash_chain; + long hlist_node_next; + long hlist_node_pprev; + long pid_pid_chain; + long thread_struct_eip; + long thread_struct_esp; + long thread_struct_ksp; + long thread_struct_fph; + long thread_struct_rip; + long thread_struct_rsp; + long thread_struct_rsp0; + long tms_tms_utime; + long tms_tms_stime; + long signal_struct_count; + long signal_struct_action; + long signal_struct_shared_pending; + long signal_struct_rlim; + long k_sigaction_sa; + long sigaction_sa_handler; + long sigaction_sa_flags; + long sigaction_sa_mask; + long sigpending_head; + long sigpending_list; + long sigpending_signal; + long signal_queue_next; + long signal_queue_info; + long sigqueue_next; + long sigqueue_list; + long sigqueue_info; + long sighand_struct_action; + long siginfo_si_signo; + long thread_struct_cr3; + long thread_struct_ptbr; + long thread_struct_pg_tables; + long switch_stack_r26; + long switch_stack_b0; + long switch_stack_ar_bspstore; + long switch_stack_ar_pfs; + long switch_stack_ar_rnat; + long switch_stack_pr; + long cpuinfo_ia64_proc_freq; + long cpuinfo_ia64_unimpl_va_mask; + long cpuinfo_ia64_unimpl_pa_mask; + long device_node_type; + long device_node_allnext; + long device_node_properties; + long property_name; + long property_value; + long property_next; + long machdep_calls_setup_residual; + long RESIDUAL_VitalProductData; + long VPD_ProcessorHz; + long bd_info_bi_intfreq; + long hwrpb_struct_cycle_freq; + long hwrpb_struct_processor_offset; + long hwrpb_struct_processor_size; + long percpu_struct_halt_PC; + long percpu_struct_halt_ra; + long percpu_struct_halt_pv; + long mm_struct_mmap; + long mm_struct_pgd; + long mm_struct_rss; + long mm_struct_anon_rss; + long mm_struct_file_rss; + long mm_struct_total_vm; + long mm_struct_start_code; + long mm_struct_arg_start; + long mm_struct_arg_end; + long mm_struct_env_start; + long mm_struct_env_end; + long vm_area_struct_vm_mm; + long vm_area_struct_vm_next; + long vm_area_struct_vm_end; + long vm_area_struct_vm_start; + long vm_area_struct_vm_flags; + long vm_area_struct_vm_file; + long vm_area_struct_vm_offset; + long vm_area_struct_vm_pgoff; + long vm_struct_addr; + long vm_struct_size; + long vm_struct_next; + long module_size_of_struct; + long module_next; + long module_size; + long module_name; + long module_nsyms; + long module_syms; + long module_flags; + long module_num_syms; + long module_list; + long module_gpl_syms; + long module_num_gpl_syms; + long module_module_core; + long module_core_size; + long module_core_text_size; + long module_num_symtab; + long module_symtab; + long module_strtab; + + long module_kallsyms_start; + long kallsyms_header_sections; + long kallsyms_header_section_off; + long kallsyms_header_symbols; + long kallsyms_header_symbol_off; + long kallsyms_header_string_off; + long kallsyms_symbol_section_off; + long kallsyms_symbol_symbol_addr; + long kallsyms_symbol_name_off; + long kallsyms_section_start; + long kallsyms_section_size; + long kallsyms_section_name_off; + + long page_next; + long page_prev; + long page_next_hash; + long page_list; + long page_list_next; + long page_list_prev; + long page_inode; + long page_offset; + long page_count; + long page_flags; + long page_mapping; + long page_index; + long page_buffers; + long page_lru; + long page_pte; + long swap_info_struct_swap_file; + long swap_info_struct_swap_vfsmnt; + long swap_info_struct_flags; + long swap_info_struct_swap_map; + long swap_info_struct_swap_device; + long swap_info_struct_prio; + long swap_info_struct_max; + long swap_info_struct_pages; + long swap_info_struct_old_block_size; + long block_device_bd_inode; + long block_device_bd_list; + long block_device_bd_disk; + long irq_desc_t_status; + long irq_desc_t_handler; + long irq_desc_t_chip; + long irq_desc_t_action; + long irq_desc_t_depth; + long irqdesc_action; + long irqdesc_ctl; + long irqdesc_level; + long irqaction_handler; + long irqaction_flags; + long irqaction_mask; + long irqaction_name; + long irqaction_dev_id; + long irqaction_next; + long hw_interrupt_type_typename; + long hw_interrupt_type_startup; + long hw_interrupt_type_shutdown; + long hw_interrupt_type_handle; + long hw_interrupt_type_enable; + long hw_interrupt_type_disable; + long hw_interrupt_type_ack; + long hw_interrupt_type_end; + long hw_interrupt_type_set_affinity; + long irq_chip_typename; + long irq_chip_startup; + long irq_chip_shutdown; + long irq_chip_enable; + long irq_chip_disable; + long irq_chip_ack; + long irq_chip_end; + long irq_chip_set_affinity; + long irq_chip_mask; + long irq_chip_mask_ack; + long irq_chip_unmask; + long irq_chip_eoi; + long irq_chip_retrigger; + long irq_chip_set_type; + long irq_chip_set_wake; + long irq_cpustat_t___softirq_active; + long irq_cpustat_t___softirq_mask; + long fdtable_max_fds; + long fdtable_max_fdset; + long fdtable_open_fds; + long fdtable_fd; + long files_struct_fdt; + long files_struct_max_fds; + long files_struct_max_fdset; + long files_struct_open_fds; + long files_struct_fd; + long files_struct_open_fds_init; + long file_f_dentry; + long file_f_vfsmnt; + long file_f_count; + long file_f_path; + long path_mnt; + long path_dentry; + long fs_struct_root; + long fs_struct_pwd; + long fs_struct_rootmnt; + long fs_struct_pwdmnt; + long dentry_d_inode; + long dentry_d_parent; + long dentry_d_name; + long dentry_d_covers; + long dentry_d_iname; + long qstr_len; + long qstr_name; + long inode_i_mode; + long inode_i_op; + long inode_i_sb; + long inode_u; + long inode_i_flock; + long inode_i_fop; + long inode_i_mapping; + long address_space_nrpages; + long vfsmount_mnt_next; + long vfsmount_mnt_devname; + long vfsmount_mnt_dirname; + long vfsmount_mnt_sb; + long vfsmount_mnt_list; + long vfsmount_mnt_mountpoint; + long vfsmount_mnt_parent; + long namespace_root; + long namespace_list; + long super_block_s_dirty; + long super_block_s_type; + long super_block_s_files; + long file_system_type_name; + long nlm_file_f_file; + long file_lock_fl_owner; + long nlm_host_h_exportent; + long svc_client_cl_ident; + long kmem_cache_s_c_nextp; + long kmem_cache_s_c_name; + long kmem_cache_s_c_num; + long kmem_cache_s_c_org_size; + long kmem_cache_s_c_flags; + long kmem_cache_s_c_offset; + long kmem_cache_s_c_firstp; + long kmem_cache_s_c_gfporder; + long kmem_cache_s_c_magic; + long kmem_cache_s_num; + long kmem_cache_s_next; + long kmem_cache_s_name; + long kmem_cache_s_objsize; + long kmem_cache_s_flags; + long kmem_cache_s_gfporder; + long kmem_cache_s_slabs; + long kmem_cache_s_slabs_full; + long kmem_cache_s_slabs_partial; + long kmem_cache_s_slabs_free; + long kmem_cache_s_cpudata; + long kmem_cache_s_c_align; + long kmem_cache_s_colour_off; + long cpucache_s_avail; + long cpucache_s_limit; + long kmem_cache_s_array; + long array_cache_avail; + long array_cache_limit; + long kmem_cache_s_lists; + long kmem_list3_slabs_partial; + long kmem_list3_slabs_full; + long kmem_list3_slabs_free; + long kmem_list3_free_objects; + long kmem_list3_shared; + long kmem_slab_s_s_nextp; + long kmem_slab_s_s_freep; + long kmem_slab_s_s_inuse; + long kmem_slab_s_s_mem; + long kmem_slab_s_s_index; + long kmem_slab_s_s_offset; + long kmem_slab_s_s_magic; + long slab_s_list; + long slab_s_s_mem; + long slab_s_inuse; + long slab_s_free; + long slab_list; + long slab_s_mem; + long slab_inuse; + long slab_free; + long net_device_next; + long net_device_name; + long net_device_type; + long net_device_addr_len; + long net_device_ip_ptr; + long net_device_dev_list; + long net_dev_base_head; + long device_next; + long device_name; + long device_type; + long device_ip_ptr; + long device_addr_len; + long socket_sk; + long sock_daddr; + long sock_rcv_saddr; + long sock_dport; + long sock_sport; + long sock_num; + long sock_type; + long sock_family; + long sock_common_skc_family; + long sock_sk_type; + long inet_sock_inet; + long inet_opt_daddr; + long inet_opt_rcv_saddr; + long inet_opt_dport; + long inet_opt_sport; + long inet_opt_num; + long ipv6_pinfo_rcv_saddr; + long ipv6_pinfo_daddr; + long timer_list_list; + long timer_list_next; + long timer_list_entry; + long timer_list_expires; + long timer_list_function; + long timer_vec_root_vec; + long timer_vec_vec; + long tvec_root_s_vec; + long tvec_s_vec; + long tvec_t_base_s_tv1; + long wait_queue_task; + long wait_queue_next; + long __wait_queue_task; + long __wait_queue_head_task_list; + long __wait_queue_task_list; + long pglist_data_node_zones; + long pglist_data_node_mem_map; + long pglist_data_node_start_paddr; + long pglist_data_node_start_mapnr; + long pglist_data_node_size; + long pglist_data_node_id; + long pglist_data_node_next; + long pglist_data_nr_zones; + long pglist_data_node_start_pfn; + long pglist_data_pgdat_next; + long pglist_data_node_present_pages; + long pglist_data_node_spanned_pages; + long pglist_data_bdata; + long page_cache_bucket_chain; + long zone_struct_free_pages; + long zone_struct_free_area; + long zone_struct_zone_pgdat; + long zone_struct_name; + long zone_struct_size; + long zone_struct_memsize; + long zone_struct_zone_start_pfn; + long zone_struct_zone_start_paddr; + long zone_struct_zone_start_mapnr; + long zone_struct_zone_mem_map; + long zone_struct_inactive_clean_pages; + long zone_struct_inactive_clean_list; + long zone_struct_inactive_dirty_pages; + long zone_struct_active_pages; + long zone_struct_pages_min; + long zone_struct_pages_low; + long zone_struct_pages_high; + long zone_free_pages; + long zone_free_area; + long zone_zone_pgdat; + long zone_zone_mem_map; + long zone_name; + long zone_spanned_pages; + long zone_zone_start_pfn; + long zone_pages_min; + long zone_pages_low; + long zone_pages_high; + long zone_vm_stat; + long neighbour_next; + long neighbour_primary_key; + long neighbour_ha; + long neighbour_dev; + long neighbour_nud_state; + long neigh_table_hash_buckets; + long neigh_table_key_len; + long in_device_ifa_list; + long in_ifaddr_ifa_next; + long in_ifaddr_ifa_address; + long pci_dev_global_list; + long pci_dev_next; + long pci_dev_bus; + long pci_dev_devfn; + long pci_dev_class; + long pci_dev_device; + long pci_dev_vendor; + long pci_bus_number; + long resource_entry_t_from; + long resource_entry_t_num; + long resource_entry_t_name; + long resource_entry_t_next; + long resource_name; + long resource_start; + long resource_end; + long resource_sibling; + long resource_child; + long runqueue_curr; + long runqueue_idle; + long runqueue_active; + long runqueue_expired; + long runqueue_arrays; + long runqueue_cpu; + long cpu_s_idle; + long cpu_s_curr; + long prio_array_nr_active; + long prio_array_queue; + long user_regs_struct_ebp; + long user_regs_struct_esp; + long user_regs_struct_rip; + long user_regs_struct_cs; + long user_regs_struct_eflags; + long user_regs_struct_rsp; + long user_regs_struct_ss; + long e820map_nr_map; + long e820entry_addr; + long e820entry_size; + long e820entry_type; + long char_device_struct_next; + long char_device_struct_name; + long char_device_struct_fops; + long char_device_struct_major; + long gendisk_major; + long gendisk_disk_name; + long gendisk_fops; + long blk_major_name_next; + long blk_major_name_major; + long blk_major_name_name; + long radix_tree_root_height; + long radix_tree_root_rnode; + long x8664_pda_pcurrent; + long x8664_pda_data_offset; + long x8664_pda_kernelstack; + long x8664_pda_irqrsp; + long x8664_pda_irqstackptr; + long x8664_pda_level4_pgt; + long x8664_pda_cpunumber; + long x8664_pda_me; + long tss_struct_ist; + long mem_section_section_mem_map; + long vcpu_guest_context_user_regs; + long cpu_user_regs_eip; + long cpu_user_regs_esp; + long cpu_user_regs_rip; + long cpu_user_regs_rsp; + long unwind_table_core; + long unwind_table_init; + long unwind_table_address; + long unwind_table_size; + long unwind_table_link; + long unwind_table_name; + long rq_cfs; + long rq_rt; + long rq_nr_running; + long cfs_rq_rb_leftmost; + long cfs_rq_nr_running; + long cfs_rq_tasks_timeline; + long task_struct_se; + long sched_entity_run_node; + long rt_rq_active; + long kmem_cache_size; + long kmem_cache_objsize; + long kmem_cache_offset; + long kmem_cache_order; + long kmem_cache_local_node; + long kmem_cache_objects; + long kmem_cache_inuse; + long kmem_cache_align; + long kmem_cache_name; + long kmem_cache_list; + long kmem_cache_node; + long kmem_cache_cpu_slab; + long page_inuse; +/* long page_offset; use "old" page->offset */ + long page_slab; + long page_first_page; + long page_freelist; + long kmem_cache_node_nr_partial; + long kmem_cache_node_nr_slabs; + long kmem_cache_node_partial; + long kmem_cache_node_full; + long pid_numbers; + long upid_nr; + long upid_ns; + long upid_pid_chain; + long pid_tasks; + long kmem_cache_cpu_freelist; + long kmem_cache_cpu_page; + long kmem_cache_cpu_node; + long kmem_cache_flags; + long zone_nr_active; + long zone_nr_inactive; + long zone_all_unreclaimable; + long zone_present_pages; + long zone_flags; + long zone_pages_scanned; + long pcpu_info_vcpu; + long pcpu_info_idle; + long vcpu_struct_rq; + long task_struct_sched_info; + long sched_info_last_arrival; + long page_objects; + long kmem_cache_oo; + long char_device_struct_cdev; + long char_device_struct_baseminor; + long cdev_ops; + long probe_next; + long probe_dev; + long probe_data; + long kobj_map_probes; + long task_struct_prio; + long zone_watermark; + long module_sect_attrs; + long module_sect_attrs_attrs; + long module_sect_attrs_nsections; + long module_sect_attr_mattr; + long module_sect_attr_name; + long module_sect_attr_address; + long module_attribute_attr; + long attribute_owner; + long module_sect_attr_attr; + long module_sections_attrs; + long swap_info_struct_inuse_pages; + long s390_lowcore_psw_save_area; + long mm_struct_rss_stat; + long mm_rss_stat_count; + long module_module_init; + long module_init_text_size; + long cpu_context_save_fp; + long cpu_context_save_sp; + long cpu_context_save_pc; + long elf_prstatus_pr_pid; + long elf_prstatus_pr_reg; + long irq_desc_t_name; + long thread_info_cpu_context; + long unwind_table_list; + long unwind_table_start; + long unwind_table_stop; + long unwind_table_begin_addr; + long unwind_table_end_addr; + long unwind_idx_addr; + long unwind_idx_insn; + long signal_struct_nr_threads; + long module_init_size; + long module_percpu; + long radix_tree_node_slots; + long s390_stack_frame_back_chain; + long s390_stack_frame_r14; + long user_regs_struct_eip; + long user_regs_struct_rax; + long user_regs_struct_eax; + long user_regs_struct_rbx; + long user_regs_struct_ebx; + long user_regs_struct_rcx; + long user_regs_struct_ecx; + long user_regs_struct_rdx; + long user_regs_struct_edx; + long user_regs_struct_rsi; + long user_regs_struct_esi; + long user_regs_struct_rdi; + long user_regs_struct_edi; + long user_regs_struct_ds; + long user_regs_struct_es; + long user_regs_struct_fs; + long user_regs_struct_gs; + long user_regs_struct_rbp; + long user_regs_struct_r8; + long user_regs_struct_r9; + long user_regs_struct_r10; + long user_regs_struct_r11; + long user_regs_struct_r12; + long user_regs_struct_r13; + long user_regs_struct_r14; + long user_regs_struct_r15; + long sched_entity_cfs_rq; + long sched_entity_my_q; + long sched_entity_on_rq; + long task_struct_on_rq; + long cfs_rq_curr; + long irq_desc_t_irq_data; + long irq_desc_t_kstat_irqs; + long irq_desc_t_affinity; + long irq_data_chip; + long irq_data_affinity; + long kernel_stat_irqs; + long socket_alloc_vfs_inode; + long class_devices; + long class_p; + long class_private_devices; + long device_knode_class; + long device_node; + long gendisk_dev; + long gendisk_kobj; + long gendisk_part0; + long gendisk_queue; + long hd_struct_dev; + long klist_k_list; + long klist_node_n_klist; + long klist_node_n_node; + long kobject_entry; + long kset_list; + long request_list_count; + long request_queue_in_flight; + long request_queue_rq; + long subsys_private_klist_devices; + long subsystem_kset; + long mount_mnt_parent; + long mount_mnt_mountpoint; + long mount_mnt_list; + long mount_mnt_devname; + long mount_mnt; + long task_struct_exit_state; + long timekeeper_xtime; + long file_f_op; + long file_private_data; + long hstate_order; + long hugetlbfs_sb_info_hstate; + long idr_layer_ary; + long idr_layer_layer; + long idr_layers; + long idr_top; + long ipc_id_ary_p; + long ipc_ids_entries; + long ipc_ids_max_id; + long ipc_ids_ipcs_idr; + long ipc_ids_in_use; + long ipc_namespace_ids; + long kern_ipc_perm_deleted; + long kern_ipc_perm_key; + long kern_ipc_perm_mode; + long kern_ipc_perm_uid; + long kern_ipc_perm_id; + long kern_ipc_perm_seq; + long nsproxy_ipc_ns; + long shmem_inode_info_swapped; + long shmem_inode_info_vfs_inode; + long shm_file_data_file; + long shmid_kernel_shm_file; + long shmid_kernel_shm_nattch; + long shmid_kernel_shm_perm; + long shmid_kernel_shm_segsz; + long shmid_kernel_id; + long sem_array_sem_perm; + long sem_array_sem_id; + long sem_array_sem_nsems; + long msg_queue_q_perm; + long msg_queue_q_id; + long msg_queue_q_cbytes; + long msg_queue_q_qnum; + long super_block_s_fs_info; + long rq_timestamp; + long radix_tree_node_height; + long rb_root_rb_node; + long rb_node_rb_left; + long rb_node_rb_right; + long rt_prio_array_queue; + long task_struct_rt; + long sched_rt_entity_run_list; + long log_ts_nsec; + long log_len; + long log_text_len; + long log_dict_len; + long log_level; + long log_flags_level; + long timekeeper_xtime_sec; + long neigh_table_hash_mask; + long sched_rt_entity_my_q; + long neigh_table_hash_shift; + long neigh_table_nht_ptr; + long task_group_parent; + long task_group_css; + long cgroup_subsys_state_cgroup; + long cgroup_dentry; + long task_group_rt_rq; + long rt_rq_tg; + long task_group_cfs_rq; + long cfs_rq_tg; + long task_group_siblings; + long task_group_children; + long task_group_cfs_bandwidth; + long cfs_rq_throttled; + long task_group_rt_bandwidth; + long rt_rq_rt_throttled; + long rt_rq_highest_prio; + long rt_rq_rt_nr_running; + long vmap_area_va_start; + long vmap_area_va_end; + long vmap_area_list; + long vmap_area_flags; + long vmap_area_vm; + long hrtimer_cpu_base_clock_base; + long hrtimer_clock_base_offset; + long hrtimer_clock_base_active; + long hrtimer_clock_base_first; + long hrtimer_clock_base_get_time; + long hrtimer_base_first; + long hrtimer_base_pending; + long hrtimer_base_get_time; + long hrtimer_node; + long hrtimer_list; + long hrtimer_softexpires; + long hrtimer_expires; + long hrtimer_function; + long timerqueue_head_next; + long timerqueue_node_expires; + long timerqueue_node_node; + long ktime_t_tv64; + long ktime_t_sec; + long ktime_t_nsec; + long module_taints; + long module_gpgsig_ok; + long module_license_gplok; + long tnt_bit; + long tnt_true; + long tnt_false; + long task_struct_thread_context_fp; + long task_struct_thread_context_sp; + long task_struct_thread_context_pc; + long page_slab_page; + long trace_print_flags_mask; + long trace_print_flags_name; + long task_struct_rss_stat; + long task_rss_stat_count; + long page_s_mem; + long page_active; +}; + +struct size_table { /* stash of commonly-used sizes */ + long page; + long free_area_struct; + long zone_struct; + long free_area; + long zone; + long kmem_slab_s; + long kmem_cache_s; + long kmem_bufctl_t; + long slab_s; + long slab; + long cpucache_s; + long array_cache; + long swap_info_struct; + long mm_struct; + long vm_area_struct; + long pglist_data; + long page_cache_bucket; + long pt_regs; + long task_struct; + long thread_info; + long softirq_state; + long desc_struct; + long umode_t; + long dentry; + long files_struct; + long fdtable; + long fs_struct; + long file; + long inode; + long vfsmount; + long super_block; + long irqdesc; + long module; + long list_head; + long hlist_node; + long hlist_head; + long irq_cpustat_t; + long cpuinfo_x86; + long cpuinfo_ia64; + long timer_list; + long timer_vec_root; + long timer_vec; + long tvec_root_s; + long tvec_s; + long tvec_t_base_s; + long wait_queue; + long __wait_queue; + long device; + long net_device; + long sock; + long signal_struct; + long sigpending_signal; + long signal_queue; + long sighand_struct; + long sigqueue; + long k_sigaction; + long resource_entry_t; + long resource; + long runqueue; + long irq_desc_t; + long task_union; + long thread_union; + long prio_array; + long user_regs_struct; + long switch_stack; + long vm_area_struct_vm_flags; + long e820map; + long e820entry; + long cpu_s; + long pgd_t; + long kallsyms_header; + long kallsyms_symbol; + long kallsyms_section; + long irq_ctx; + long block_device; + long blk_major_name; + long gendisk; + long address_space; + long char_device_struct; + long inet_sock; + long in6_addr; + long socket; + long spinlock_t; + long radix_tree_root; + long radix_tree_node; + long x8664_pda; + long ppc64_paca; + long gate_struct; + long tss_struct; + long task_struct_start_time; + long cputime_t; + long mem_section; + long pid_link; + long unwind_table; + long rlimit; + long kmem_cache; + long kmem_cache_node; + long upid; + long kmem_cache_cpu; + long cfs_rq; + long pcpu_info; + long vcpu_struct; + long cdev; + long probe; + long kobj_map; + long page_flags; + long module_sect_attr; + long task_struct_utime; + long task_struct_stime; + long cpu_context_save; + long elf_prstatus; + long note_buf; + long unwind_idx; + long softirq_action; + long irq_data; + long s390_stack_frame; + long percpu_data; + long sched_entity; + long kernel_stat; + long subsystem; + long class_private; + long rq_in_flight; + long class_private_devices; + long mount; + long hstate; + long ipc_ids; + long shmid_kernel; + long sem_array; + long msg_queue; + long log; + long log_level; + long rt_rq; + long task_group; + long vmap_area; + long hrtimer_clock_base; + long hrtimer_base; + long tnt; + long trace_print_flags; +}; + +struct array_table { + int kmem_cache_s_name; + int kmem_cache_s_c_name; + int kmem_cache_s_array; + int kmem_cache_s_cpudata; + int irq_desc; + int irq_action; + int log_buf; + int timer_vec_vec; + int timer_vec_root_vec; + int tvec_s_vec; + int tvec_root_s_vec; + int page_hash_table; + int net_device_name; + int neigh_table_hash_buckets; + int neighbour_ha; + int swap_info; + int pglist_data_node_zones; + int zone_struct_free_area; + int zone_free_area; + int free_area; + int free_area_DIMENSION; + int prio_array_queue; + int height_to_maxindex; + int pid_hash; + int kmem_cache_node; + int kmem_cache_cpu_slab; + int rt_prio_array_queue; +}; + +/* + * The following set of macros use gdb to determine structure, union, + * or member sizes/offsets. They should be used only during initialization + * of the offset_table or size_table, or with data structures whose names + * or members are only known/specified during runtime. + */ +#define MEMBER_SIZE_REQUEST ((struct datatype_member *)(-1)) +#define ANON_MEMBER_OFFSET_REQUEST ((struct datatype_member *)(-2)) +#define MEMBER_TYPE_REQUEST ((struct datatype_member *)(-3)) +#define STRUCT_SIZE_REQUEST ((struct datatype_member *)(-4)) + +#define STRUCT_SIZE(X) datatype_info((X), NULL, STRUCT_SIZE_REQUEST) +#define UNION_SIZE(X) datatype_info((X), NULL, STRUCT_SIZE_REQUEST) +#define STRUCT_EXISTS(X) (datatype_info((X), NULL, STRUCT_SIZE_REQUEST) >= 0) +#define DATATYPE_SIZE(X) datatype_info((X)->name, NULL, (X)) +#define MEMBER_OFFSET(X,Y) datatype_info((X), (Y), NULL) +#define MEMBER_EXISTS(X,Y) (datatype_info((X), (Y), NULL) >= 0) +#define MEMBER_SIZE(X,Y) datatype_info((X), (Y), MEMBER_SIZE_REQUEST) +#define MEMBER_TYPE(X,Y) datatype_info((X), (Y), MEMBER_TYPE_REQUEST) +#define ANON_MEMBER_OFFSET(X,Y) datatype_info((X), (Y), ANON_MEMBER_OFFSET_REQUEST) + +/* + * The following set of macros can only be used with pre-intialized fields + * in the offset table, size table or array_table. + */ +#define OFFSET(X) (OFFSET_verify(offset_table.X, (char *)__FUNCTION__, __FILE__, __LINE__, #X)) +#define SIZE(X) (SIZE_verify(size_table.X, (char *)__FUNCTION__, __FILE__, __LINE__, #X)) +#define INVALID_OFFSET (-1) +#define INVALID_MEMBER(X) (offset_table.X == INVALID_OFFSET) +#define INVALID_SIZE(X) (size_table.X == -1) +#define VALID_SIZE(X) (size_table.X >= 0) +#define VALID_STRUCT(X) (size_table.X >= 0) +#define VALID_MEMBER(X) (offset_table.X >= 0) +#define ARRAY_LENGTH(X) (array_table.X) +#define ASSIGN_OFFSET(X) (offset_table.X) +#define ASSIGN_SIZE(X) (size_table.X) +#define OFFSET_OPTION(X,Y) (OFFSET_option(offset_table.X, offset_table.Y, (char *)__FUNCTION__, __FILE__, __LINE__, #X, #Y)) +#define SIZE_OPTION(X,Y) (SIZE_option(size_table.X, size_table.Y, (char *)__FUNCTION__, __FILE__, __LINE__, #X, #Y)) + +#define MEMBER_OFFSET_INIT(X, Y, Z) (ASSIGN_OFFSET(X) = MEMBER_OFFSET(Y, Z)) +#define STRUCT_SIZE_INIT(X, Y) (ASSIGN_SIZE(X) = STRUCT_SIZE(Y)) +#define ARRAY_LENGTH_INIT(A, B, C, D, E) ((A) = get_array_length(C, D, E)) +#define ARRAY_LENGTH_INIT_ALT(A, B, C, D, E) ((A) = get_array_length_alt(B, C, D, E)) +#define MEMBER_SIZE_INIT(X, Y, Z) (ASSIGN_SIZE(X) = MEMBER_SIZE(Y, Z)) +#define ANON_MEMBER_OFFSET_INIT(X, Y, Z) (ASSIGN_OFFSET(X) = ANON_MEMBER_OFFSET(Y, Z)) + +/* + * For use with non-debug kernels. + */ +struct builtin_debug_table { + char *release; + char *machine_type; + struct offset_table *offset_table; + struct size_table *size_table; + struct array_table *array_table; +}; + +/* + * Facilitators for pulling correctly-sized data out of a buffer at a + * known address. + */ +#define INT(ADDR) *((int *)((char *)(ADDR))) +#define UINT(ADDR) *((uint *)((char *)(ADDR))) +#define LONG(ADDR) *((long *)((char *)(ADDR))) +#define ULONG(ADDR) *((ulong *)((char *)(ADDR))) +#define ULONGLONG(ADDR) *((ulonglong *)((char *)(ADDR))) +#define ULONG_PTR(ADDR) *((ulong **)((char *)(ADDR))) +#define USHORT(ADDR) *((ushort *)((char *)(ADDR))) +#define SHORT(ADDR) *((short *)((char *)(ADDR))) +#define UCHAR(ADDR) *((unsigned char *)((char *)(ADDR))) +#define VOID_PTR(ADDR) *((void **)((char *)(ADDR))) + +struct node_table { + int node_id; + ulong pgdat; + ulong mem_map; + ulong size; + ulong present; + ulonglong start_paddr; + ulong start_mapnr; +}; + +struct meminfo; +struct slab_data; + +#define VMA_CACHE (20) + +struct vm_table { /* kernel VM-related data */ + ulong flags; + ulong kernel_pgd[NR_CPUS]; + ulong high_memory; + ulong vmalloc_start; + ulong mem_map; + long total_pages; + ulong totalram_pages; + ulong totalhigh_pages; + ulong num_physpages; + ulong max_mapnr; + ulong kmem_max_c_num; + ulong kmem_max_limit; + ulong kmem_max_cpus; + ulong kmem_cache_count; + ulong kmem_cache_len_nodes; + ulong PG_reserved; + ulong PG_slab; + ulong PG_head_tail_mask; + int kmem_cache_namelen; + ulong page_hash_table; + int page_hash_table_len; + int paddr_prlen; + int numnodes; + int nr_zones; + int nr_free_areas; + struct node_table *node_table; + void (*dump_free_pages)(struct meminfo *); + void (*dump_kmem_cache)(struct meminfo *); + struct slab_data *slab_data; + uint nr_swapfiles; + ulong last_swap_read; + char *swap_info_struct; + char *vma_cache; + ulong cached_vma[VMA_CACHE]; + ulong cached_vma_hits[VMA_CACHE]; + int vma_cache_index; + ulong vma_cache_fills; + void *mem_sec; + char *mem_section; + int ZONE_HIGHMEM; + ulong *node_online_map; + int node_online_map_len; + int nr_vm_stat_items; + char **vm_stat_items; + int cpu_slab_type; + int nr_vm_event_items; + char **vm_event_items; + int nr_bad_slab_caches; + ulong *bad_slab_caches; + int nr_pageflags; + struct pageflags_data { + ulong mask; + char *name; + } *pageflags_data; +}; + +#define NODES (0x1) +#define ZONES (0x2) +#define PERCPU_KMALLOC_V1 (0x4) +#define COMMON_VADDR (0x8) +#define KMEM_CACHE_INIT (0x10) +#define V_MEM_MAP (0x20) +#define PERCPU_KMALLOC_V2 (0x40) +#define KMEM_CACHE_UNAVAIL (0x80) +#define FLATMEM (0x100) +#define DISCONTIGMEM (0x200) +#define SPARSEMEM (0x400) +#define SPARSEMEM_EX (0x800) +#define PERCPU_KMALLOC_V2_NODES (0x1000) +#define KMEM_CACHE_DELAY (0x2000) +#define NODES_ONLINE (0x4000) +#define VM_STAT (0x8000) +#define KMALLOC_SLUB (0x10000) +#define CONFIG_NUMA (0x20000) +#define VM_EVENT (0x40000) +#define PGCNT_ADJ (0x80000) +#define VM_INIT (0x100000) +#define SWAPINFO_V1 (0x200000) +#define SWAPINFO_V2 (0x400000) +#define NODELISTS_IS_PTR (0x800000) +#define KMALLOC_COMMON (0x1000000) +#define USE_VMAP_AREA (0x2000000) +#define PAGEFLAGS (0x4000000) +#define SLAB_OVERLOAD_PAGE (0x8000000) + +#define IS_FLATMEM() (vt->flags & FLATMEM) +#define IS_DISCONTIGMEM() (vt->flags & DISCONTIGMEM) +#define IS_SPARSEMEM() (vt->flags & SPARSEMEM) +#define IS_SPARSEMEM_EX() (vt->flags & SPARSEMEM_EX) + +#define COMMON_VADDR_SPACE() (vt->flags & COMMON_VADDR) +#define PADDR_PRLEN (vt->paddr_prlen) + +struct datatype_member { /* minimal definition of a structure/union */ + char *name; /* and possibly a member within it */ + char *member; + ulong type; + long size; + long member_offset; + long member_size; + int member_typecode; + ulong flags; + char *tagname; /* tagname and value for enums */ + long value; + ulong vaddr; +}; + +#define union_name struct_name + +struct list_data { /* generic structure used by do_list() to walk */ + ulong flags; /* through linked lists in the kernel */ + ulong start; + long member_offset; + long list_head_offset; + ulong end; + ulong searchfor; + char **structname; + int structname_args; + char *header; + ulong *list_ptr; +}; +#define LIST_OFFSET_ENTERED (VERBOSE << 1) +#define LIST_START_ENTERED (VERBOSE << 2) +#define LIST_HEAD_FORMAT (VERBOSE << 3) +#define LIST_HEAD_POINTER (VERBOSE << 4) +#define RETURN_ON_DUPLICATE (VERBOSE << 5) +#define RETURN_ON_LIST_ERROR (VERBOSE << 6) +#define LIST_STRUCT_RADIX_10 (VERBOSE << 7) +#define LIST_STRUCT_RADIX_16 (VERBOSE << 8) +#define LIST_HEAD_REVERSE (VERBOSE << 9) +#define LIST_ALLOCATE (VERBOSE << 10) + +struct tree_data { + ulong flags; + ulong start; + long node_member_offset; + char **structname; + int structname_args; + int count; +}; + +#define TREE_ROOT_OFFSET_ENTERED (VERBOSE << 1) +#define TREE_NODE_OFFSET_ENTERED (VERBOSE << 2) +#define TREE_NODE_POINTER (VERBOSE << 3) +#define TREE_POSITION_DISPLAY (VERBOSE << 4) +#define TREE_STRUCT_RADIX_10 (VERBOSE << 5) +#define TREE_STRUCT_RADIX_16 (VERBOSE << 6) + +#define ALIAS_RUNTIME (1) +#define ALIAS_RCLOCAL (2) +#define ALIAS_RCHOME (3) +#define ALIAS_BUILTIN (4) + +struct alias_data { /* command alias storage */ + struct alias_data *next; + char *alias; + int argcnt; + int size; + int origin; + char *args[MAXARGS]; + char argbuf[1]; +}; + +struct rb_node +{ + unsigned long rb_parent_color; +#define RB_RED 0 +#define RB_BLACK 1 + struct rb_node *rb_right; + struct rb_node *rb_left; +}; + +struct rb_root +{ + struct rb_node *rb_node; +}; + +#define NUMBER_STACKFRAMES 4 + +#define SAVE_RETURN_ADDRESS(retaddr) \ +{ \ + int i; \ + int saved_stacks; \ + \ + saved_stacks = backtrace((void **)retaddr, NUMBER_STACKFRAMES); \ + \ + /* explicitely zero out the invalid addresses */ \ + for (i = saved_stacks; i < NUMBER_STACKFRAMES; i++) \ + retaddr[i] = 0; \ +} + +#endif /* !GDB_COMMON */ + + +#define SYMBOL_NAME_USED (0x1) +#define MODULE_SYMBOL (0x2) +#define IS_MODULE_SYMBOL(SYM) ((SYM)->flags & MODULE_SYMBOL) + +struct syment { + ulong value; + char *name; + struct syment *val_hash_next; + struct syment *name_hash_next; + char type; + unsigned char cnt; + unsigned char flags; + unsigned char pad2; +}; + +#define NAMESPACE_INIT (1) +#define NAMESPACE_REUSE (2) +#define NAMESPACE_FREE (3) +#define NAMESPACE_INSTALL (4) +#define NAMESPACE_COMPLETE (5) + +struct symbol_namespace { + char *address; + size_t size; + long index; + long cnt; +}; + +#define SYMVAL_HASH (512) +#define SYMVAL_HASH_INDEX(vaddr) \ + (((vaddr) >> machdep->pageshift) % SYMVAL_HASH) + +#define SYMNAME_HASH (512) +#define SYMNAME_HASH_INDEX(name) \ + ((name[0] ^ (name[strlen(name)-1] * name[strlen(name)/2])) % SYMNAME_HASH) + +#define PATCH_KERNEL_SYMBOLS_START ((char *)(1)) +#define PATCH_KERNEL_SYMBOLS_STOP ((char *)(2)) + +#ifndef GDB_COMMON + +struct symbol_table_data { + ulong flags; +#ifdef GDB_5_3 + struct _bfd *bfd; +#else + struct bfd *bfd; +#endif + struct sec *sections; + struct syment *symtable; + struct syment *symend; + long symcnt; + ulong syment_size; + struct symval_hash_chain { + struct syment *val_hash_head; + struct syment *val_hash_last; + } symval_hash[SYMVAL_HASH]; + double val_hash_searches; + double val_hash_iterations; + struct syment *symname_hash[SYMNAME_HASH]; + struct symbol_namespace kernel_namespace; + struct syment *ext_module_symtable; + struct syment *ext_module_symend; + long ext_module_symcnt; + struct symbol_namespace ext_module_namespace; + int mods_installed; + struct load_module *current; + struct load_module *load_modules; + off_t dwarf_eh_frame_file_offset; + ulong dwarf_eh_frame_size; + ulong first_ksymbol; + ulong __per_cpu_start; + ulong __per_cpu_end; + off_t dwarf_debug_frame_file_offset; + ulong dwarf_debug_frame_size; +}; + +/* flags for st */ +#define KERNEL_SYMS (0x1) +#define MODULE_SYMS (0x2) +#define LOAD_MODULE_SYMS (0x4) +#define INSMOD_BUILTIN (0x8) +#define GDB_SYMS_PATCHED (0x10) +#define GDB_PATCHED() (st->flags & GDB_SYMS_PATCHED) +#define NO_SEC_LOAD (0x20) +#define NO_SEC_CONTENTS (0x40) +#define FORCE_DEBUGINFO (0x80) +#define CRC_MATCHES (0x100) +#define ADD_SYMBOL_FILE (0x200) +#define USE_OLD_ADD_SYM (0x400) +#define PERCPU_SYMS (0x800) +#define MODSECT_UNKNOWN (0x1000) +#define MODSECT_V1 (0x2000) +#define MODSECT_V2 (0x4000) +#define MODSECT_V3 (0x8000) +#define MODSECT_VMASK (MODSECT_V1|MODSECT_V2|MODSECT_V3) +#define NO_STRIP (0x10000) + +#endif /* !GDB_COMMON */ + +#define ALL_MODULES (0) + +#define MAX_MOD_NAMELIST (256) +#define MAX_MOD_NAME (64) +#define MAX_MOD_SEC_NAME (64) + +#define MOD_EXT_SYMS (0x1) +#define MOD_LOAD_SYMS (0x2) +#define MOD_REMOTE (0x4) +#define MOD_KALLSYMS (0x8) +#define MOD_INITRD (0x10) +#define MOD_NOPATCH (0x20) +#define MOD_INIT (0x40) +#define MOD_DO_READNOW (0x80) + +#define SEC_FOUND (0x10000) + +struct mod_section_data { +#if defined(GDB_5_3) || defined(GDB_6_0) + struct sec *section; +#else + struct bfd_section *section; +#endif + char name[MAX_MOD_SEC_NAME]; + ulong offset; + ulong size; + int priority; + int flags; +}; + +struct load_module { + ulong mod_base; + ulong module_struct; + long mod_size; + char mod_namelist[MAX_MOD_NAMELIST]; + char mod_name[MAX_MOD_NAME]; + ulong mod_flags; + struct syment *mod_symtable; + struct syment *mod_symend; + long mod_ext_symcnt; + struct syment *mod_ext_symtable; + struct syment *mod_ext_symend; + long mod_load_symcnt; + struct syment *mod_load_symtable; + struct syment *mod_load_symend; + long mod_symalloc; + struct symbol_namespace mod_load_namespace; + ulong mod_size_of_struct; + ulong mod_text_start; + ulong mod_etext_guess; + ulong mod_rodata_start; + ulong mod_data_start; + ulong mod_bss_start; + int mod_sections; + struct mod_section_data *mod_section_data; + ulong mod_init_text_size; + ulong mod_init_module_ptr; + ulong mod_init_size; + struct syment *mod_init_symtable; + struct syment *mod_init_symend; + ulong mod_percpu; + ulong mod_percpu_size; +}; + +#define IN_MODULE(A,L) \ + (((ulong)(A) >= (L)->mod_base) && ((ulong)(A) < ((L)->mod_base+(L)->mod_size))) + +#define IN_MODULE_INIT(A,L) \ + (((ulong)(A) >= (L)->mod_init_module_ptr) && ((ulong)(A) < ((L)->mod_init_module_ptr+(L)->mod_init_size))) + +#define IN_MODULE_PERCPU(A,L) \ + (((ulong)(A) >= (L)->mod_percpu) && ((ulong)(A) < ((L)->mod_percpu+(L)->mod_percpu_size))) + +#define MODULE_PERCPU_SYMS_LOADED(L) ((L)->mod_percpu && (L)->mod_percpu_size) + +#ifndef GDB_COMMON + +#define KVADDR (0x1) +#define UVADDR (0x2) +#define PHYSADDR (0x4) +#define XENMACHADDR (0x8) +#define FILEADDR (0x10) +#define AMBIGUOUS (~0) + +#define USE_USER_PGD (UVADDR << 2) + +#define VERIFY_ADDR (0x8) /* vm_area_dump() flags -- must follow */ +#define PRINT_INODES (0x10) /* KVADDR, UVADDR, and PHYSADDR */ +#define PRINT_MM_STRUCT (0x20) +#define PRINT_VMA_STRUCTS (0x40) +#define PRINT_SINGLE_VMA (0x80) +#define PRINT_RADIX_10 (0x100) +#define PRINT_RADIX_16 (0x200) + +#define MIN_PAGE_SIZE (4096) + +#define PTOB(X) ((ulonglong)(X) << machdep->pageshift) +#define BTOP(X) ((ulonglong)(X) >> machdep->pageshift) + +#define PAGESIZE() (machdep->pagesize) +#define PAGESHIFT() (machdep->pageshift) + +#define PAGEOFFSET(X) (((ulong)(X)) & machdep->pageoffset) +#define VIRTPAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) +#define PHYSPAGEBASE(X) (((physaddr_t)(X)) & (physaddr_t)machdep->pagemask) + +/* + * Sparse memory stuff + * These must follow the definitions in the kernel mmzone.h + */ +#define SECTION_SIZE_BITS() (machdep->section_size_bits) +#define MAX_PHYSMEM_BITS() (machdep->max_physmem_bits) +#define SECTIONS_SHIFT() (MAX_PHYSMEM_BITS() - SECTION_SIZE_BITS()) +#define PA_SECTION_SHIFT() (SECTION_SIZE_BITS()) +#define PFN_SECTION_SHIFT() (SECTION_SIZE_BITS() - PAGESHIFT()) +#define NR_MEM_SECTIONS() (1UL << SECTIONS_SHIFT()) +#define PAGES_PER_SECTION() (1UL << PFN_SECTION_SHIFT()) +#define PAGE_SECTION_MASK() (~(PAGES_PER_SECTION()-1)) + +#define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT()) +#define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT()) + +#define SECTIONS_PER_ROOT() (machdep->sections_per_root) + +/* CONFIG_SPARSEMEM_EXTREME */ +#define _SECTIONS_PER_ROOT_EXTREME() (PAGESIZE() / SIZE(mem_section)) +/* !CONFIG_SPARSEMEM_EXTREME */ +#define _SECTIONS_PER_ROOT() (1) + +#define SECTION_NR_TO_ROOT(sec) ((sec) / SECTIONS_PER_ROOT()) +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) +#define NR_SECTION_ROOTS() (DIV_ROUND_UP(NR_MEM_SECTIONS(), SECTIONS_PER_ROOT())) +#define SECTION_ROOT_MASK() (SECTIONS_PER_ROOT() - 1) + +/* + * Machine specific stuff + */ + +#ifdef ARM +#define _32BIT_ +#define MACHINE_TYPE "ARM" + +#define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) + +#define PTOV(X) \ + ((unsigned long)(X)-(machdep->machspec->phys_base)+(machdep->kvbase)) +#define VTOP(X) \ + ((unsigned long)(X)-(machdep->kvbase)+(machdep->machspec->phys_base)) + +#define IS_VMALLOC_ADDR(X) arm_is_vmalloc_addr((ulong)(X)) + +#define DEFAULT_MODULES_VADDR (machdep->kvbase - 16 * 1024 * 1024) +#define MODULES_VADDR (machdep->machspec->modules_vaddr) +#define MODULES_END (machdep->machspec->modules_end) +#define VMALLOC_START (machdep->machspec->vmalloc_start_addr) +#define VMALLOC_END (machdep->machspec->vmalloc_end) + +#define PGDIR_SHIFT (21) +#define PTRS_PER_PTE (512) +#define PTRS_PER_PGD (2048) + +#define PGD_OFFSET(vaddr) ((vaddr) >> PGDIR_SHIFT) +#define PTE_OFFSET(vaddr) (((vaddr) >> PAGESHIFT()) & (PTRS_PER_PTE - 1)) + +#define __SWP_TYPE_SHIFT 3 +#define __SWP_TYPE_BITS 6 +#define __SWP_TYPE_MASK ((1 << __SWP_TYPE_BITS) - 1) +#define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT) + +#define SWP_TYPE(entry) (((entry) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK) +#define SWP_OFFSET(entry) ((entry) >> __SWP_OFFSET_SHIFT) + +#define __swp_type(entry) SWP_TYPE(entry) +#define __swp_offset(entry) SWP_OFFSET(entry) + +#define TIF_SIGPENDING (2) + +#define _SECTION_SIZE_BITS 28 +#define _MAX_PHYSMEM_BITS 32 + +#endif /* ARM */ + +#ifndef EM_AARCH64 +#define EM_AARCH64 183 +#endif + +#ifdef ARM64 +#define _64BIT_ +#define MACHINE_TYPE "ARM64" + +#define PTOV(X) \ + ((unsigned long)(X)-(machdep->machspec->phys_offset)+(machdep->kvbase)) +#define VTOP(X) \ + ((unsigned long)(X)-(machdep->kvbase)+(machdep->machspec->phys_offset)) + +#define USERSPACE_TOP (machdep->machspec->userspace_top) +#define PAGE_OFFSET (machdep->machspec->page_offset) +#define VMALLOC_START (machdep->machspec->vmalloc_start_addr) +#define VMALLOC_END (machdep->machspec->vmalloc_end) +#define VMEMMAP_VADDR (machdep->machspec->vmemmap_vaddr) +#define VMEMMAP_END (machdep->machspec->vmemmap_end) +#define MODULES_VADDR (machdep->machspec->modules_vaddr) +#define MODULES_END (machdep->machspec->modules_end) + +#define IS_VMALLOC_ADDR(X) arm64_IS_VMALLOC_ADDR((ulong)(X)) + +#define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) + +/* + * 40-bit physical address supported. (512GB) + */ +#define PHYS_MASK_SHIFT (40) +#define PHYS_MASK (((1UL) << PHYS_MASK_SHIFT) - 1) + +typedef signed int s32; + +/* + * 3-levels / 4K pages + */ +#define PTRS_PER_PGD_L3_4K (512) +#define PTRS_PER_PMD_L3_4K (512) +#define PTRS_PER_PTE_L3_4K (512) +#define PGDIR_SHIFT_L3_4K (30) +#define PGDIR_SIZE_L3_4K ((1UL) << PGDIR_SHIFT_L3_4K) +#define PGDIR_MASK_L3 4K (~(PGDIR_SIZE_L3_4K-1)) +#define PMD_SHIFT_L3_4K (21) +#define PMD_SIZE_L3_4K (1UL << PMD_SHIFT_4K) +#define PMD_MASK_L3 4K (~(PMD_SIZE_4K-1)) + +/* + * 2-levels / 64K pages + */ +#define PTRS_PER_PGD_L2_64K (1024) +#define PTRS_PER_PTE_L2_64K (8192) +#define PGDIR_SHIFT_L2_64K (29) +#define PGDIR_SIZE_L2_64K ((1UL) << PGDIR_SHIFT_L2_64K) +#define PGDIR_MASK_L2_64K (~(PGDIR_SIZE_L2_64K-1)) + +/* + * Software defined PTE bits definition. + * (arch/arm64/include/asm/pgtable.h) + */ +#define PTE_VALID (1UL << 0) +#define PTE_PROT_NONE (1UL << 1) /* only when !PTE_VALID */ +#define PTE_FILE (1UL << 2) /* only when !pte_present() */ +#define PTE_DIRTY (1UL << 55) +#define PTE_SPECIAL (1UL << 56) + +/* + * HugeTLB/THP 3.10 support proposal swaps PTE_PROT_NONE + * and PTE_FILE bit positions: + */ +#define PTE_FILE_3_10 (1UL << 1) +#define PTE_PROT_NONE_3_10 (1UL << 2) + +/* + * Level 3 descriptor (PTE). + * (arch/arm64/include/asm/pgtable-hwdef.h) + */ +#define PTE_TYPE_MASK (3UL << 0) +#define PTE_TYPE_FAULT (0UL << 0) +#define PTE_TYPE_PAGE (3UL << 0) +#define PTE_USER (1UL << 6) /* AP[1] */ +#define PTE_RDONLY (1UL << 7) /* AP[2] */ +#define PTE_SHARED (3UL << 8) /* SH[1:0], inner shareable */ +#define PTE_AF (1UL << 10) /* Access Flag */ +#define PTE_NG (1UL << 11) /* nG */ +#define PTE_PXN (1UL << 53) /* Privileged XN */ +#define PTE_UXN (1UL << 54) /* User XN */ + +/* + * swap entry: + * bits 0-1: present (must be zero) + * bit 2: PTE_FILE + * bits 3-8: swap type + * bits 9-63: swap offset + * + * HugeTLB/THP 3.10 support proposal swaps PTE_PROT_NONE + * and PTE_FILE bit positions: + * + * bits 0, 2: present (must both be zero) + * bit 1: PTE_FILE + * bits 3-8: swap type + * bits 9-63: swap offset + */ +#define __SWP_TYPE_SHIFT 3 +#define __SWP_TYPE_BITS 6 +#define __SWP_TYPE_MASK ((1 << __SWP_TYPE_BITS) - 1) +#define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT) + +#define __swp_type(x) (((x) >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK) +#define __swp_offset(x) ((x) >> __SWP_OFFSET_SHIFT) +#define SWP_TYPE(x) __swp_type(x) +#define SWP_OFFSET(x) __swp_offset(x) + +#define KSYMS_START (0x1) +#define PHYS_OFFSET (0x2) +#define VM_L2_64K (0x4) +#define VM_L3_4K (0x8) + +/* + * source: Documentation/arm64/memory.txt + */ +#define ARM64_USERSPACE_TOP (0x0000007fffffffffUL) +#define ARM64_VMALLOC_START (0xffffff8000000000UL) +#define ARM64_VMALLOC_END (0xffffffbbfffeffffUL) +#define ARM64_VMEMMAP_VADDR (0xffffffbc00000000UL) +#define ARM64_VMEMMAP_END (0xffffffbffbbfffffUL) +#define ARM64_MODULES_VADDR (0xffffffbffc000000UL) +#define ARM64_MODULES_END (0xffffffbfffffffffUL) +#define ARM64_PAGE_OFFSET (0xffffffc000000000UL) + +#define ARM64_STACK_SIZE (8192) + +#define _SECTION_SIZE_BITS 30 +#define _MAX_PHYSMEM_BITS 40 + +typedef unsigned long long __u64; +typedef unsigned long long u64; + +struct arm64_user_pt_regs { + __u64 regs[31]; + __u64 sp; + __u64 pc; + __u64 pstate; +}; + +struct arm64_pt_regs { + union { + struct arm64_user_pt_regs user_regs; + struct { + u64 regs[31]; + u64 sp; + u64 pc; + u64 pstate; + }; + }; + u64 orig_x0; + u64 syscallno; +}; + +#define TIF_SIGPENDING (0) +#define display_idt_table() \ + error(FATAL, "-d option is not applicable to ARM64 architecture\n") + +struct machine_specific { + ulong flags; + ulong userspace_top; + ulong page_offset; + ulong vmalloc_start_addr; + ulong vmalloc_end; + ulong vmemmap_vaddr; + ulong vmemmap_end; + ulong modules_vaddr; + ulong modules_end; + ulong phys_offset; + ulong __exception_text_start; + ulong __exception_text_end; + struct arm64_pt_regs *panic_task_regs; + ulong pte_protnone; + ulong pte_file; +}; + +struct arm64_stackframe { + unsigned long fp; + unsigned long sp; + unsigned long pc; +}; + +#endif /* ARM64 */ + +#ifdef X86 +#define _32BIT_ +#define MACHINE_TYPE "X86" +#define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) +#define VTOP(X) ((unsigned long)(X)-(machdep->kvbase)) +#define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) +#define KVBASE_MASK (0x1ffffff) + +#define PGDIR_SHIFT_2LEVEL (22) +#define PTRS_PER_PTE_2LEVEL (1024) +#define PTRS_PER_PGD_2LEVEL (1024) + +#define PGDIR_SHIFT_3LEVEL (30) +#define PTRS_PER_PTE_3LEVEL (512) +#define PTRS_PER_PGD_3LEVEL (4) +#define PMD_SHIFT (21) /* only used by PAE translators */ +#define PTRS_PER_PMD (512) /* only used by PAE translators */ + +#define _PAGE_PRESENT 0x001 +#define _PAGE_RW 0x002 +#define _PAGE_USER 0x004 +#define _PAGE_PWT 0x008 +#define _PAGE_PCD 0x010 +#define _PAGE_ACCESSED 0x020 +#define _PAGE_DIRTY 0x040 +#define _PAGE_4M 0x080 /* 4 MB page, Pentium+, if present.. */ +#define _PAGE_PSE 0x080 /* 4 MB (or 2MB) page, Pentium+, if present.. */ +#define _PAGE_GLOBAL 0x100 /* Global TLB entry PPro+ */ +#define _PAGE_PROTNONE (machdep->machspec->page_protnone) +#define _PAGE_NX (0x8000000000000000ULL) + +#define NONPAE_PAGEBASE(X) (((unsigned long)(X)) & (unsigned long)machdep->pagemask) +#define NX_BIT_MASK (0x7fffffffffffffffULL) +#define PAE_PAGEBASE(X) (((unsigned long long)(X)) & ((unsigned long long)machdep->pagemask) & NX_BIT_MASK) + +#define SWP_TYPE(entry) (((entry) >> 1) & 0x3f) +#define SWP_OFFSET(entry) ((entry) >> 8) +#define __swp_type_PAE(entry) (((entry) >> 32) & 0x1f) +#define __swp_type_nonPAE(entry) (((entry) >> 1) & 0x1f) +#define __swp_offset_PAE(entry) (((entry) >> 32) >> 5) +#define __swp_offset_nonPAE(entry) ((entry) >> 8) +#define __swp_type(entry) (machdep->flags & PAE ? \ + __swp_type_PAE(entry) : __swp_type_nonPAE(entry)) +#define __swp_offset(entry) (machdep->flags & PAE ? \ + __swp_offset_PAE(entry) : __swp_offset_nonPAE(entry)) + +#define TIF_SIGPENDING (2) + +// CONFIG_X86_PAE +#define _SECTION_SIZE_BITS_PAE_ORIG 30 +#define _SECTION_SIZE_BITS_PAE_2_6_26 29 +#define _MAX_PHYSMEM_BITS_PAE 36 + +// !CONFIG_X86_PAE +#define _SECTION_SIZE_BITS 26 +#define _MAX_PHYSMEM_BITS 32 + +#define IS_LAST_PMD_READ_PAE(pmd) ((ulong)(pmd) == machdep->machspec->last_pmd_read_PAE) +#define IS_LAST_PTBL_READ_PAE(ptbl) ((ulong)(ptbl) == machdep->machspec->last_ptbl_read_PAE) + +#define FILL_PMD_PAE(PMD, TYPE, SIZE) \ + if (!IS_LAST_PMD_READ_PAE(PMD)) { \ + readmem((ulonglong)(PMD), TYPE, machdep->pmd, \ + SIZE, "pmd page", FAULT_ON_ERROR); \ + machdep->machspec->last_pmd_read_PAE = (ulonglong)(PMD); \ + } + +#define FILL_PTBL_PAE(PTBL, TYPE, SIZE) \ + if (!IS_LAST_PTBL_READ_PAE(PTBL)) { \ + readmem((ulonglong)(PTBL), TYPE, machdep->ptbl, \ + SIZE, "page table", FAULT_ON_ERROR); \ + machdep->machspec->last_ptbl_read_PAE = (ulonglong)(PTBL); \ + } + +#endif /* X86 */ + +#ifdef X86_64 +#define _64BIT_ +#define MACHINE_TYPE "X86_64" + +#define USERSPACE_TOP (machdep->machspec->userspace_top) +#define PAGE_OFFSET (machdep->machspec->page_offset) +#define VMALLOC_START (machdep->machspec->vmalloc_start_addr) +#define VMALLOC_END (machdep->machspec->vmalloc_end) +#define VMEMMAP_VADDR (machdep->machspec->vmemmap_vaddr) +#define VMEMMAP_END (machdep->machspec->vmemmap_end) +#define MODULES_VADDR (machdep->machspec->modules_vaddr) +#define MODULES_END (machdep->machspec->modules_end) + +#define __START_KERNEL_map 0xffffffff80000000UL +#define MODULES_LEN (MODULES_END - MODULES_VADDR) + +#define USERSPACE_TOP_ORIG 0x0000008000000000 +#define PAGE_OFFSET_ORIG 0x0000010000000000 +#define VMALLOC_START_ADDR_ORIG 0xffffff0000000000 +#define VMALLOC_END_ORIG 0xffffff7fffffffff +#define MODULES_VADDR_ORIG 0xffffffffa0000000 +#define MODULES_END_ORIG 0xffffffffafffffff + +#define USERSPACE_TOP_2_6_11 0x0000800000000000 +#define PAGE_OFFSET_2_6_11 0xffff810000000000 +#define VMALLOC_START_ADDR_2_6_11 0xffffc20000000000 +#define VMALLOC_END_2_6_11 0xffffe1ffffffffff +#define MODULES_VADDR_2_6_11 0xffffffff88000000 +#define MODULES_END_2_6_11 0xfffffffffff00000 + +#define VMEMMAP_VADDR_2_6_24 0xffffe20000000000 +#define VMEMMAP_END_2_6_24 0xffffe2ffffffffff + +#define MODULES_VADDR_2_6_26 0xffffffffa0000000 + +#define PAGE_OFFSET_2_6_27 0xffff880000000000 +#define MODULES_END_2_6_27 0xffffffffff000000 + +#define USERSPACE_TOP_XEN 0x0000800000000000 +#define PAGE_OFFSET_XEN 0xffff880000000000 +#define VMALLOC_START_ADDR_XEN 0xffffc20000000000 +#define VMALLOC_END_XEN 0xffffe1ffffffffff +#define MODULES_VADDR_XEN 0xffffffff88000000 +#define MODULES_END_XEN 0xfffffffffff00000 + +#define USERSPACE_TOP_XEN_RHEL4 0x0000008000000000 +#define PAGE_OFFSET_XEN_RHEL4 0xffffff8000000000 +#define VMALLOC_START_ADDR_XEN_RHEL4 0xffffff0000000000 +#define VMALLOC_END_XEN_RHEL4 0xffffff7fffffffff +#define MODULES_VADDR_XEN_RHEL4 0xffffffffa0000000 +#define MODULES_END_XEN_RHEL4 0xffffffffafffffff + +#define VMALLOC_START_ADDR_2_6_31 0xffffc90000000000 +#define VMALLOC_END_2_6_31 0xffffe8ffffffffff +#define VMEMMAP_VADDR_2_6_31 0xffffea0000000000 +#define VMEMMAP_END_2_6_31 0xffffeaffffffffff +#define MODULES_VADDR_2_6_31 0xffffffffa0000000 +#define MODULES_END_2_6_31 0xffffffffff000000 + +#define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) +#define VTOP(X) x86_64_VTOP((ulong)(X)) +#define IS_VMALLOC_ADDR(X) x86_64_IS_VMALLOC_ADDR((ulong)(X)) + +#define PML4_SHIFT 39 +#define PTRS_PER_PML4 512 +#define PGDIR_SHIFT 30 +#define PTRS_PER_PGD 512 +#define PMD_SHIFT 21 +#define PTRS_PER_PMD 512 +#define PTRS_PER_PTE 512 + +#define pml4_index(address) (((address) >> PML4_SHIFT) & (PTRS_PER_PML4-1)) +#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1)) +#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)) +#define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) + +#define IS_LAST_PML4_READ(pml4) ((ulong)(pml4) == machdep->machspec->last_pml4_read) + +#define FILL_PML4() { \ + if (!(pc->flags & RUNTIME) || ACTIVE()) \ + if (!IS_LAST_PML4_READ(vt->kernel_pgd[0])) \ + readmem(vt->kernel_pgd[0], KVADDR, machdep->machspec->pml4, \ + PAGESIZE(), "init_level4_pgt", FAULT_ON_ERROR); \ + machdep->machspec->last_pml4_read = (ulong)(vt->kernel_pgd[0]); \ + } + +#define FILL_PML4_HYPER() { \ + if (!machdep->machspec->last_pml4_read) { \ + unsigned long idle_pg_table = \ + symbol_exists("idle_pg_table_4") ? symbol_value("idle_pg_table_4") : \ + symbol_value("idle_pg_table"); \ + readmem(idle_pg_table, KVADDR, \ + machdep->machspec->pml4, PAGESIZE(), "idle_pg_table", \ + FAULT_ON_ERROR); \ + machdep->machspec->last_pml4_read = idle_pg_table; \ + }\ +} + +#define IS_LAST_UPML_READ(pml) ((ulong)(pml) == machdep->machspec->last_upml_read) + +#define FILL_UPML(PML, TYPE, SIZE) \ + if (!IS_LAST_UPML_READ(PML)) { \ + readmem((ulonglong)((ulong)(PML)), TYPE, machdep->machspec->upml, \ + SIZE, "pml page", FAULT_ON_ERROR); \ + machdep->machspec->last_upml_read = (ulong)(PML); \ + } + +/* + * PHYSICAL_PAGE_MASK changed (enlarged) between 2.4 and 2.6, so + * for safety, use the 2.6 values to generate it. + */ +#define __PHYSICAL_MASK_SHIFT 40 +#define __PHYSICAL_MASK ((1UL << __PHYSICAL_MASK_SHIFT) - 1) +#define __VIRTUAL_MASK_SHIFT 48 +#define __VIRTUAL_MASK ((1UL << __VIRTUAL_MASK_SHIFT) - 1) +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PHYSICAL_PAGE_MASK (~(PAGE_SIZE-1) & (__PHYSICAL_MASK << PAGE_SHIFT)) + +#define _PAGE_BIT_NX 63 +#define _PAGE_PRESENT 0x001 +#define _PAGE_RW 0x002 +#define _PAGE_USER 0x004 +#define _PAGE_PWT 0x008 +#define _PAGE_PCD 0x010 +#define _PAGE_ACCESSED 0x020 +#define _PAGE_DIRTY 0x040 +#define _PAGE_PSE 0x080 /* 2MB page */ +#define _PAGE_FILE 0x040 /* set:pagecache, unset:swap */ +#define _PAGE_GLOBAL 0x100 /* Global TLB entry */ +#define _PAGE_PROTNONE (machdep->machspec->page_protnone) +#define _PAGE_NX (1UL<<_PAGE_BIT_NX) + +#define SWP_TYPE(entry) (((entry) >> 1) & 0x3f) +#define SWP_OFFSET(entry) ((entry) >> 8) +#define __swp_type(entry) SWP_TYPE(entry) +#define __swp_offset(entry) SWP_OFFSET(entry) + +#define TIF_SIGPENDING (2) + +#define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) + +#define _CPU_PDA_READ2(CPU, BUFFER) \ + ((readmem(symbol_value("_cpu_pda"), \ + KVADDR, &cpu_pda_addr, sizeof(unsigned long), \ + "_cpu_pda addr", RETURN_ON_ERROR)) && \ + (readmem(cpu_pda_addr + ((CPU) * sizeof(void *)), \ + KVADDR, &cpu_pda_addr, sizeof(unsigned long), \ + "_cpu_pda addr", RETURN_ON_ERROR)) && \ + (cpu_pda_addr) && \ + (readmem(cpu_pda_addr, KVADDR, (BUFFER), SIZE(x8664_pda), \ + "cpu_pda entry", RETURN_ON_ERROR))) + +#define _CPU_PDA_READ(CPU, BUFFER) \ + ((STRNEQ("_cpu_pda", closest_symbol((symbol_value("_cpu_pda") + \ + ((CPU) * sizeof(unsigned long)))))) && \ + (readmem(symbol_value("_cpu_pda") + ((CPU) * sizeof(void *)), \ + KVADDR, &cpu_pda_addr, sizeof(unsigned long), \ + "_cpu_pda addr", RETURN_ON_ERROR)) && \ + (readmem(cpu_pda_addr, KVADDR, (BUFFER), SIZE(x8664_pda), \ + "cpu_pda entry", RETURN_ON_ERROR))) + +#define CPU_PDA_READ(CPU, BUFFER) \ + (STRNEQ("cpu_pda", closest_symbol((symbol_value("cpu_pda") + \ + ((CPU) * SIZE(x8664_pda))))) && \ + readmem(symbol_value("cpu_pda") + ((CPU) * SIZE(x8664_pda)), \ + KVADDR, (BUFFER), SIZE(x8664_pda), "cpu_pda entry", \ + RETURN_ON_ERROR)) + +#define VALID_LEVEL4_PGT_ADDR(X) \ + (((X) == VIRTPAGEBASE(X)) && IS_KVADDR(X) && !IS_VMALLOC_ADDR(X)) + +#define _SECTION_SIZE_BITS 27 +#define _MAX_PHYSMEM_BITS 40 +#define _MAX_PHYSMEM_BITS_2_6_26 44 +#define _MAX_PHYSMEM_BITS_2_6_31 46 + +#endif /* X86_64 */ + +#ifdef ALPHA +#define _64BIT_ +#define MACHINE_TYPE "ALPHA" + +#define PAGEBASE(X) (((unsigned long)(X)) & (unsigned long)machdep->pagemask) + +#define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) +#define VTOP(X) ((unsigned long)(X)-(machdep->kvbase)) +#define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) +#define KSEG_BASE_48_BIT (0xffff800000000000) +#define KSEG_BASE (0xfffffc0000000000) +#define _PFN_MASK (0xFFFFFFFF00000000) +#define VMALLOC_START (0xFFFFFE0000000000) +#define MIN_SYMBOL_VALUE (KSEG_BASE_48_BIT) + +#define PGDIR_SHIFT (PAGESHIFT() + 2*(PAGESHIFT()-3)) +#define PMD_SHIFT (PAGESHIFT() + (PAGESHIFT()-3)) +#define PTRS_PER_PAGE (1024) + +#define PTRS_PER_PGD (1UL << (PAGESHIFT()-3)) + +/* + * OSF/1 PAL-code-imposed page table bits + */ +#define _PAGE_VALID 0x0001 +#define _PAGE_FOR 0x0002 /* used for page protection (fault on read) */ +#define _PAGE_FOW 0x0004 /* used for page protection (fault on write) */ +#define _PAGE_FOE 0x0008 /* used for page protection (fault on exec) */ +#define _PAGE_ASM 0x0010 +#define _PAGE_KRE 0x0100 /* xxx - see below on the "accessed" bit */ +#define _PAGE_URE 0x0200 /* xxx */ +#define _PAGE_KWE 0x1000 /* used to do the dirty bit in software */ +#define _PAGE_UWE 0x2000 /* used to do the dirty bit in software */ + +/* .. and these are ours ... */ +#define _PAGE_DIRTY 0x20000 +#define _PAGE_ACCESSED 0x40000 + +#define SWP_TYPE(entry) (((entry) >> 32) & 0xff) +#define SWP_OFFSET(entry) ((entry) >> 40) +#define __swp_type(entry) SWP_TYPE(entry) +#define __swp_offset(entry) SWP_OFFSET(entry) + +#define TIF_SIGPENDING (2) + +#endif /* ALPHA */ + +#ifdef PPC +#define _32BIT_ +#define MACHINE_TYPE "PPC" + +#define PAGEBASE(X) ((X) & machdep->pagemask) + +#define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) +#define VTOP(X) ((unsigned long)(X)-(machdep->kvbase)) +#define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) + +/* Holds the platform specific info for page translation */ +struct machine_specific { + char *platform; + + /* page address translation bits */ + int pte_size; + int pte_rpn_shift; + + /* page flags */ + ulong _page_present; + ulong _page_user; + ulong _page_rw; + ulong _page_guarded; + ulong _page_coherent; + ulong _page_no_cache; + ulong _page_writethru; + ulong _page_dirty; + ulong _page_accessed; + ulong _page_hwwrite; + ulong _page_shared; + ulong _page_k_rw; + + /* platform special vtop */ + int (*vtop_special)(ulong vaddr, physaddr_t *paddr, int verbose); + void *mmu_special; +}; + +/* machdep flags for ppc32 specific */ +#define IS_PAE() (machdep->flags & PAE) +#define IS_BOOKE() (machdep->flags & CPU_BOOKE) +/* Page translation bits */ +#define PPC_PLATFORM (machdep->machspec->platform) +#define PTE_SIZE (machdep->machspec->pte_size) +#define PTE_RPN_SHIFT (machdep->machspec->pte_rpn_shift) +#define PAGE_SHIFT (12) +#define PTE_T_LOG2 (ffs(PTE_SIZE) - 1) +#define PTE_SHIFT (PAGE_SHIFT - PTE_T_LOG2) +#define PGDIR_SHIFT (PAGE_SHIFT + PTE_SHIFT) +#define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT)) +#define PTRS_PER_PTE (1 << PTE_SHIFT) +/* special vtop */ +#define VTOP_SPECIAL (machdep->machspec->vtop_special) +#define MMU_SPECIAL (machdep->machspec->mmu_special) + +/* PFN shifts */ +#define BOOKE3E_PTE_RPN_SHIFT (24) + +/* PAGE flags */ +#define _PAGE_PRESENT (machdep->machspec->_page_present) /* software: pte contains a translation */ +#define _PAGE_USER (machdep->machspec->_page_user) /* matches one of the PP bits */ +#define _PAGE_RW (machdep->machspec->_page_rw) /* software: user write access allowed */ +#define _PAGE_GUARDED (machdep->machspec->_page_guarded) +#define _PAGE_COHERENT (machdep->machspec->_page_coherent /* M: enforce memory coherence (SMP systems) */) +#define _PAGE_NO_CACHE (machdep->machspec->_page_no_cache) /* I: cache inhibit */ +#define _PAGE_WRITETHRU (machdep->machspec->_page_writethru) /* W: cache write-through */ +#define _PAGE_DIRTY (machdep->machspec->_page_dirty) /* C: page changed */ +#define _PAGE_ACCESSED (machdep->machspec->_page_accessed) /* R: page referenced */ +#define _PAGE_HWWRITE (machdep->machspec->_page_hwwrite) /* software: _PAGE_RW & _PAGE_DIRTY */ +#define _PAGE_SHARED (machdep->machspec->_page_shared) +#define _PAGE_K_RW (machdep->machspec->_page_k_rw) /* privilege only write access allowed */ + +/* Default values for PAGE flags */ +#define DEFAULT_PAGE_PRESENT 0x001 +#define DEFAULT_PAGE_USER 0x002 +#define DEFAULT_PAGE_RW 0x004 +#define DEFAULT_PAGE_GUARDED 0x008 +#define DEFAULT_PAGE_COHERENT 0x010 +#define DEFAULT_PAGE_NO_CACHE 0x020 +#define DEFAULT_PAGE_WRITETHRU 0x040 +#define DEFAULT_PAGE_DIRTY 0x080 +#define DEFAULT_PAGE_ACCESSED 0x100 +#define DEFAULT_PAGE_HWWRITE 0x200 +#define DEFAULT_PAGE_SHARED 0 + +/* PPC44x PAGE flags: Values from kernel asm/pte-44x.h */ +#define PPC44x_PAGE_PRESENT 0x001 +#define PPC44x_PAGE_RW 0x002 +#define PPC44x_PAGE_ACCESSED 0x008 +#define PPC44x_PAGE_DIRTY 0x010 +#define PPC44x_PAGE_USER 0x040 +#define PPC44x_PAGE_GUARDED 0x100 +#define PPC44x_PAGE_COHERENT 0x200 +#define PPC44x_PAGE_NO_CACHE 0x400 +#define PPC44x_PAGE_WRITETHRU 0x800 +#define PPC44x_PAGE_HWWRITE 0 +#define PPC44x_PAGE_SHARED 0 + +/* BOOK3E */ +#define BOOK3E_PAGE_PRESENT 0x000001 +#define BOOK3E_PAGE_BAP_SR 0x000004 +#define BOOK3E_PAGE_BAP_UR 0x000008 /* User Readable */ +#define BOOK3E_PAGE_BAP_SW 0x000010 +#define BOOK3E_PAGE_BAP_UW 0x000020 /* User Writable */ +#define BOOK3E_PAGE_DIRTY 0x001000 +#define BOOK3E_PAGE_ACCESSED 0x040000 +#define BOOK3E_PAGE_GUARDED 0x100000 +#define BOOK3E_PAGE_COHERENT 0x200000 +#define BOOK3E_PAGE_NO_CACHE 0x400000 +#define BOOK3E_PAGE_WRITETHRU 0x800000 +#define BOOK3E_PAGE_HWWRITE 0 +#define BOOK3E_PAGE_SHARED 0 +#define BOOK3E_PAGE_USER (BOOK3E_PAGE_BAP_SR | BOOK3E_PAGE_BAP_UR) +#define BOOK3E_PAGE_RW (BOOK3E_PAGE_BAP_SW | BOOK3E_PAGE_BAP_UW) +#define BOOK3E_PAGE_KERNEL_RW (BOOK3E_PAGE_BAP_SW | BOOK3E_PAGE_BAP_SR | BOOK3E_PAGE_DIRTY) + +/* FSL BOOKE */ +#define FSL_BOOKE_PAGE_PRESENT 0x00001 +#define FSL_BOOKE_PAGE_USER 0x00002 +#define FSL_BOOKE_PAGE_RW 0x00004 +#define FSL_BOOKE_PAGE_DIRTY 0x00008 +#define FSL_BOOKE_PAGE_ACCESSED 0x00020 +#define FSL_BOOKE_PAGE_GUARDED 0x00080 +#define FSL_BOOKE_PAGE_COHERENT 0x00100 +#define FSL_BOOKE_PAGE_NO_CACHE 0x00200 +#define FSL_BOOKE_PAGE_WRITETHRU 0x00400 +#define FSL_BOOKE_PAGE_HWWRITE 0 +#define FSL_BOOKE_PAGE_SHARED 0 + +#define SWP_TYPE(entry) (((entry) >> 1) & 0x7f) +#define SWP_OFFSET(entry) ((entry) >> 8) +#define __swp_type(entry) SWP_TYPE(entry) +#define __swp_offset(entry) SWP_OFFSET(entry) + +#define TIF_SIGPENDING (2) + +#define _SECTION_SIZE_BITS 24 +#define _MAX_PHYSMEM_BITS 44 + +#define STACK_FRAME_OVERHEAD 16 +#define STACK_FRAME_LR_SAVE (sizeof(ulong)) +#define STACK_FRAME_MARKER (2 * sizeof(ulong)) +#define STACK_FRAME_REGS_MARKER 0x72656773 +#define PPC_STACK_SIZE 8192 + +#endif /* PPC */ + +#ifdef IA64 +#define _64BIT_ +#define MACHINE_TYPE "IA64" + +#define PAGEBASE(X) (((unsigned long)(X)) & (unsigned long)machdep->pagemask) + +#define REGION_SHIFT (61) +#define VADDR_REGION(X) ((ulong)(X) >> REGION_SHIFT) + +#define KERNEL_CACHED_REGION (7) +#define KERNEL_UNCACHED_REGION (6) +#define KERNEL_VMALLOC_REGION (5) +#define USER_STACK_REGION (4) +#define USER_DATA_REGION (3) +#define USER_TEXT_REGION (2) +#define USER_SHMEM_REGION (1) +#define USER_IA32_EMUL_REGION (0) + +#define KERNEL_VMALLOC_BASE ((ulong)KERNEL_VMALLOC_REGION << REGION_SHIFT) +#define KERNEL_UNCACHED_BASE ((ulong)KERNEL_UNCACHED_REGION << REGION_SHIFT) +#define KERNEL_CACHED_BASE ((ulong)KERNEL_CACHED_REGION << REGION_SHIFT) + +#define _SECTION_SIZE_BITS 30 +#define _MAX_PHYSMEM_BITS 50 + +/* + * As of 2.6, these are no longer straight forward. + */ +#define PTOV(X) ia64_PTOV((ulong)(X)) +#define VTOP(X) ia64_VTOP((ulong)(X)) +#define IS_VMALLOC_ADDR(X) ia64_IS_VMALLOC_ADDR((ulong)(X)) + +#define SWITCH_STACK_ADDR(X) (ia64_get_switch_stack((ulong)(X))) + +#define __IA64_UL(x) ((unsigned long)(x)) +#define IA64_MAX_PHYS_BITS (50) /* max # of phys address bits (architected) */ + +/* + * How many pointers will a page table level hold expressed in shift + */ +#define PTRS_PER_PTD_SHIFT (PAGESHIFT()-3) + +/* + * Definitions for fourth level: + */ +#define PTRS_PER_PTE (__IA64_UL(1) << (PTRS_PER_PTD_SHIFT)) + +/* + * Definitions for third level: + * + * PMD_SHIFT determines the size of the area a third-level page table + * can map. + */ +#define PMD_SHIFT (PAGESHIFT() + (PTRS_PER_PTD_SHIFT)) +#define PMD_SIZE (1UL << PMD_SHIFT) +#define PMD_MASK (~(PMD_SIZE-1)) +#define PTRS_PER_PMD (1UL << (PTRS_PER_PTD_SHIFT)) + +/* + * PUD_SHIFT determines the size of the area a second-level page table + * can map + */ +#define PUD_SHIFT (PMD_SHIFT + (PTRS_PER_PTD_SHIFT)) +#define PUD_SIZE (1UL << PUD_SHIFT) +#define PUD_MASK (~(PUD_SIZE-1)) +#define PTRS_PER_PUD (1UL << (PTRS_PER_PTD_SHIFT)) + +/* + * Definitions for first level: + * + * PGDIR_SHIFT determines what a first-level page table entry can map. + */ + +#define PGDIR_SHIFT_4L (PUD_SHIFT + (PTRS_PER_PTD_SHIFT)) +#define PGDIR_SHIFT_3L (PMD_SHIFT + (PTRS_PER_PTD_SHIFT)) +/* Turns out 4L & 3L PGDIR_SHIFT are the same (for now) */ +#define PGDIR_SHIFT PGDIR_SHIFT_4L +#define PGDIR_SIZE (__IA64_UL(1) << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE-1)) +#define PTRS_PER_PGD_SHIFT PTRS_PER_PTD_SHIFT +#define PTRS_PER_PGD (1UL << PTRS_PER_PGD_SHIFT) +#define USER_PTRS_PER_PGD (5*PTRS_PER_PGD/8) /* regions 0-4 are user regions */ +#define FIRST_USER_ADDRESS 0 + +/* + * First, define the various bits in a PTE. Note that the PTE format + * matches the VHPT short format, the firt doubleword of the VHPD long + * format, and the first doubleword of the TLB insertion format. + */ +#define _PAGE_P (1 << 0) /* page present bit */ +#define _PAGE_MA_WB (0x0 << 2) /* write back memory attribute */ +#define _PAGE_MA_UC (0x4 << 2) /* uncacheable memory attribute */ +#define _PAGE_MA_UCE (0x5 << 2) /* UC exported attribute */ +#define _PAGE_MA_WC (0x6 << 2) /* write coalescing memory attribute */ +#define _PAGE_MA_NAT (0x7 << 2) /* not-a-thing attribute */ +#define _PAGE_MA_MASK (0x7 << 2) +#define _PAGE_PL_0 (0 << 7) /* privilege level 0 (kernel) */ +#define _PAGE_PL_1 (1 << 7) /* privilege level 1 (unused) */ +#define _PAGE_PL_2 (2 << 7) /* privilege level 2 (unused) */ +#define _PAGE_PL_3 (3 << 7) /* privilege level 3 (user) */ +#define _PAGE_PL_MASK (3 << 7) +#define _PAGE_AR_R (0 << 9) /* read only */ +#define _PAGE_AR_RX (1 << 9) /* read & execute */ +#define _PAGE_AR_RW (2 << 9) /* read & write */ +#define _PAGE_AR_RWX (3 << 9) /* read, write & execute */ +#define _PAGE_AR_R_RW (4 << 9) /* read / read & write */ +#define _PAGE_AR_RX_RWX (5 << 9) /* read & exec / read, write & exec */ +#define _PAGE_AR_RWX_RW (6 << 9) /* read, write & exec / read & write */ +#define _PAGE_AR_X_RX (7 << 9) /* exec & promote / read & exec */ +#define _PAGE_AR_MASK (7 << 9) +#define _PAGE_AR_SHIFT 9 +#define _PAGE_A (1 << 5) /* page accessed bit */ +#define _PAGE_D (1 << 6) /* page dirty bit */ +#define _PAGE_PPN_MASK (((__IA64_UL(1) << IA64_MAX_PHYS_BITS) - 1) & ~0xfffUL) +#define _PAGE_ED (__IA64_UL(1) << 52) /* exception deferral */ +#define _PAGE_PROTNONE (__IA64_UL(1) << 63) + +#define _PFN_MASK _PAGE_PPN_MASK +#define _PAGE_CHG_MASK (_PFN_MASK | _PAGE_A | _PAGE_D) + +#define _PAGE_SIZE_4K 12 +#define _PAGE_SIZE_8K 13 +#define _PAGE_SIZE_16K 14 +#define _PAGE_SIZE_64K 16 +#define _PAGE_SIZE_256K 18 +#define _PAGE_SIZE_1M 20 +#define _PAGE_SIZE_4M 22 +#define _PAGE_SIZE_16M 24 +#define _PAGE_SIZE_64M 26 +#define _PAGE_SIZE_256M 28 + +#define __ACCESS_BITS _PAGE_ED | _PAGE_A | _PAGE_P | _PAGE_MA_WB +#define __DIRTY_BITS_NO_ED _PAGE_A | _PAGE_P | _PAGE_D | _PAGE_MA_WB +#define __DIRTY_BITS _PAGE_ED | __DIRTY_BITS_NO_ED + +#define EFI_PAGE_SHIFT (12) + +/* + * NOTE: #include'ing creates too many compiler problems, so + * this stuff is hardwired here; it's probably etched in stone somewhere. + */ +struct efi_memory_desc_t { + uint32_t type; + uint32_t pad; + uint64_t phys_addr; + uint64_t virt_addr; + uint64_t num_pages; + uint64_t attribute; +} desc; + +/* Memory types: */ +#define EFI_RESERVED_TYPE 0 +#define EFI_LOADER_CODE 1 +#define EFI_LOADER_DATA 2 +#define EFI_BOOT_SERVICES_CODE 3 +#define EFI_BOOT_SERVICES_DATA 4 +#define EFI_RUNTIME_SERVICES_CODE 5 +#define EFI_RUNTIME_SERVICES_DATA 6 +#define EFI_CONVENTIONAL_MEMORY 7 +#define EFI_UNUSABLE_MEMORY 8 +#define EFI_ACPI_RECLAIM_MEMORY 9 +#define EFI_ACPI_MEMORY_NVS 10 +#define EFI_MEMORY_MAPPED_IO 11 +#define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12 +#define EFI_PAL_CODE 13 +#define EFI_MAX_MEMORY_TYPE 14 + +/* Attribute values: */ +#define EFI_MEMORY_UC 0x0000000000000001 /* uncached */ +#define EFI_MEMORY_WC 0x0000000000000002 /* write-coalescing */ +#define EFI_MEMORY_WT 0x0000000000000004 /* write-through */ +#define EFI_MEMORY_WB 0x0000000000000008 /* write-back */ +#define EFI_MEMORY_WP 0x0000000000001000 /* write-protect */ +#define EFI_MEMORY_RP 0x0000000000002000 /* read-protect */ +#define EFI_MEMORY_XP 0x0000000000004000 /* execute-protect */ +#define EFI_MEMORY_RUNTIME 0x8000000000000000 /* range requires runtime mapping */ + +#define SWP_TYPE(entry) (((entry) >> 1) & 0xff) +#define SWP_OFFSET(entry) ((entry) >> 9) +#define __swp_type(entry) ((entry >> 2) & 0x7f) +#define __swp_offset(entry) ((entry << 1) >> 10) + +#define TIF_SIGPENDING (1) + +#define KERNEL_TR_PAGE_SIZE (1 << _PAGE_SIZE_64M) +#define KERNEL_TR_PAGE_MASK (~(KERNEL_TR_PAGE_SIZE - 1)) + +#define UNKNOWN_PHYS_START ((ulong)(-1)) +#define DEFAULT_PHYS_START (KERNEL_TR_PAGE_SIZE * 1) + +#define IA64_GET_STACK_ULONG(OFF) \ + ((INSTACK(OFF,bt)) ? (GET_STACK_ULONG(OFF)) : get_init_stack_ulong((unsigned long)OFF)) + +#endif /* IA64 */ + +#ifdef PPC64 +#define _64BIT_ +#define MACHINE_TYPE "PPC64" + +#define PPC64_64K_PAGE_SIZE 65536 +#define PPC64_STACK_SIZE 16384 + +#define PAGEBASE(X) (((ulong)(X)) & (ulong)machdep->pagemask) + +#define PTOV(X) ((unsigned long)(X)+(machdep->identity_map_base)) +#define VTOP(X) ((unsigned long)(X)-(machdep->identity_map_base)) +#define BOOK3E_VMBASE 0x8000000000000000 +#define IS_VMALLOC_ADDR(X) machdep->machspec->is_vmaddr(X) +#define KERNELBASE machdep->pageoffset + +#define PGDIR_SHIFT (machdep->pageshift + (machdep->pageshift -3) + (machdep->pageshift - 2)) +#define PMD_SHIFT (machdep->pageshift + (machdep->pageshift - 3)) + +#define PGD_MASK (~((1UL << PGDIR_SHIFT) - 1)) +#define PMD_MASK (~((1UL << PMD_SHIFT) - 1)) + +/* shift to put page number into pte */ +#define PTE_SHIFT 16 +#define PMD_TO_PTEPAGE_SHIFT 2 /* Used for 2.6 or later */ + +#define PTE_INDEX_SIZE 9 +#define PMD_INDEX_SIZE 10 +#define PGD_INDEX_SIZE 10 + +#define PTRS_PER_PTE (1 << PTE_INDEX_SIZE) +#define PTRS_PER_PMD (1 << PMD_INDEX_SIZE) +#define PTRS_PER_PGD (1 << PGD_INDEX_SIZE) + +#define PGD_OFFSET_24(vaddr) ((vaddr >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1)) +#define PGD_OFFSET(vaddr) ((vaddr >> PGDIR_SHIFT) & 0x7ff) +#define PMD_OFFSET(vaddr) ((vaddr >> PMD_SHIFT) & (PTRS_PER_PMD - 1)) + +/* 4-level page table support */ + +/* 4K pagesize */ +#define PTE_INDEX_SIZE_L4_4K 9 +#define PMD_INDEX_SIZE_L4_4K 7 +#define PUD_INDEX_SIZE_L4_4K 7 +#define PGD_INDEX_SIZE_L4_4K 9 +#define PTE_SHIFT_L4_4K 17 +#define PMD_MASKED_BITS_4K 0 + +/* 64K pagesize */ +#define PTE_INDEX_SIZE_L4_64K 12 +#define PMD_INDEX_SIZE_L4_64K 12 +#define PUD_INDEX_SIZE_L4_64K 0 +#define PGD_INDEX_SIZE_L4_64K 4 +#define PTE_INDEX_SIZE_L4_64K_3_10 8 +#define PMD_INDEX_SIZE_L4_64K_3_10 10 +#define PGD_INDEX_SIZE_L4_64K_3_10 12 +#define PTE_SHIFT_L4_64K_V1 32 +#define PTE_SHIFT_L4_64K_V2 30 +#define PTE_SHIFT_L4_BOOK3E_64K 28 +#define PTE_SHIFT_L4_BOOK3E_4K 24 +#define PMD_MASKED_BITS_64K 0x1ff + +#define PD_HUGE 0x8000000000000000 +#define HUGE_PTE_MASK 0x03 +#define HUGEPD_SHIFT_MASK 0x3f +#define L4_MASK (THIS_KERNEL_VERSION >= LINUX(3,10,0) ? 0xfff : 0x1ff) +#define L4_OFFSET(vaddr) ((vaddr >> (machdep->machspec->l4_shift)) & L4_MASK) + +#define PGD_OFFSET_L4(vaddr) \ + ((vaddr >> (machdep->machspec->l3_shift)) & (machdep->machspec->ptrs_per_l3 - 1)) + +#define PMD_OFFSET_L4(vaddr) \ + ((vaddr >> (machdep->machspec->l2_shift)) & (machdep->machspec->ptrs_per_l2 - 1)) + +#define _PAGE_PRESENT (machdep->machspec->_page_present) /* software: pte contains a translation */ +#define _PAGE_USER (machdep->machspec->_page_user) /* matches one of the PP bits */ +#define _PAGE_RW (machdep->machspec->_page_rw) /* software: user write access allowed */ +#define _PAGE_GUARDED (machdep->machspec->_page_guarded) +#define _PAGE_COHERENT (machdep->machspec->_page_coherent /* M: enforce memory coherence (SMP systems) */) +#define _PAGE_NO_CACHE (machdep->machspec->_page_no_cache) /* I: cache inhibit */ +#define _PAGE_WRITETHRU (machdep->machspec->_page_writethru) /* W: cache write-through */ +#define _PAGE_DIRTY (machdep->machspec->_page_dirty) /* C: page changed */ +#define _PAGE_ACCESSED (machdep->machspec->_page_accessed) /* R: page referenced */ + +#define TIF_SIGPENDING (2) + +#define SWP_TYPE(entry) (((entry) >> 1) & 0x7f) +#define SWP_OFFSET(entry) ((entry) >> 8) +#define __swp_type(entry) SWP_TYPE(entry) +#define __swp_offset(entry) SWP_OFFSET(entry) + +#define MSR_PR_LG 14 /* Problem State / Privilege Level */ + /* Used to find the user or kernel-mode frame*/ + +#define STACK_FRAME_OVERHEAD 112 +#define EXCP_FRAME_MARKER 0x7265677368657265 + +#define _SECTION_SIZE_BITS 24 +#define _MAX_PHYSMEM_BITS 44 +#define _MAX_PHYSMEM_BITS_3_7 46 + +#endif /* PPC64 */ + +#ifdef S390 +#define _32BIT_ +#define MACHINE_TYPE "S390" + +#define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) +#define VTOP(X) ((unsigned long)(X)-(machdep->kvbase)) +#define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) + +#define PTRS_PER_PTE 1024 +#define PTRS_PER_PMD 1 +#define PTRS_PER_PGD 512 +#define SEGMENT_TABLE_SIZE ((sizeof(ulong)*4) * PTRS_PER_PGD) + +#define SWP_TYPE(entry) (((entry) >> 2) & 0x1f) +#define SWP_OFFSET(entry) ((((entry) >> 11) & 0xfffffffe) | \ + (((entry) >> 7) & 0x1)) +#define __swp_type(entry) SWP_TYPE(entry) +#define __swp_offset(entry) SWP_OFFSET(entry) + +#define TIF_SIGPENDING (2) + +#define _SECTION_SIZE_BITS 25 +#define _MAX_PHYSMEM_BITS 31 + +#endif /* S390 */ + +#ifdef S390X +#define _64BIT_ +#define MACHINE_TYPE "S390X" + +#define PTOV(X) ((unsigned long)(X)+(machdep->kvbase)) +#define VTOP(X) ((unsigned long)(X)-(machdep->kvbase)) +#define IS_VMALLOC_ADDR(X) (vt->vmalloc_start && (ulong)(X) >= vt->vmalloc_start) +#define PTRS_PER_PTE 512 +#define PTRS_PER_PMD 1024 +#define PTRS_PER_PGD 2048 +#define SEGMENT_TABLE_SIZE ((sizeof(ulong)*2) * PTRS_PER_PMD) + +#define SWP_TYPE(entry) (((entry) >> 2) & 0x1f) +#define SWP_OFFSET(entry) ((((entry) >> 11) & 0xfffffffffffffffe) | \ + (((entry) >> 7) & 0x1)) +#define __swp_type(entry) SWP_TYPE(entry) +#define __swp_offset(entry) SWP_OFFSET(entry) + +#define TIF_SIGPENDING (2) + +#define _SECTION_SIZE_BITS 28 +#define _MAX_PHYSMEM_BITS_OLD 42 +#define _MAX_PHYSMEM_BITS_NEW 46 + +#endif /* S390X */ + +#ifdef PLATFORM + +#define SWP_TYPE(entry) (error("PLATFORM_SWP_TYPE: TBD\n")) +#define SWP_OFFSET(entry) (error("PLATFORM_SWP_OFFSET: TBD\n")) +#define __swp_type(entry) SWP_TYPE(entry) +#define __swp_offset(entry) SWP_OFFSET(entry) + +#endif /* PLATFORM */ + +#define KILOBYTES(x) ((x) * (1024)) +#define MEGABYTES(x) ((x) * (1048576)) +#define GIGABYTES(x) ((x) * (1073741824)) + +#define MEGABYTE_MASK (MEGABYTES(1)-1) + +#define SIZEOF_64BIT (8) +#define SIZEOF_32BIT (4) +#define SIZEOF_16BIT (2) +#define SIZEOF_8BIT (1) + +#ifdef ARM +#define MAX_HEXADDR_STRLEN (8) +#define UVADDR_PRLEN (8) +#endif +#ifdef X86 +#define MAX_HEXADDR_STRLEN (8) +#define UVADDR_PRLEN (8) +#endif +#ifdef ALPHA +#define MAX_HEXADDR_STRLEN (16) +#define UVADDR_PRLEN (11) +#endif +#ifdef PPC +#define MAX_HEXADDR_STRLEN (8) +#define UVADDR_PRLEN (8) +#endif +#ifdef IA64 +#define MAX_HEXADDR_STRLEN (16) +#define UVADDR_PRLEN (16) +#endif +#ifdef S390 +#define MAX_HEXADDR_STRLEN (8) +#define UVADDR_PRLEN (8) +#endif +#ifdef S390X +#define MAX_HEXADDR_STRLEN (16) +#define UVADDR_PRLEN (16) +#endif +#ifdef X86_64 +#define MAX_HEXADDR_STRLEN (16) +#define UVADDR_PRLEN (10) +#endif +#ifdef PPC64 +#define MAX_HEXADDR_STRLEN (16) +#define UVADDR_PRLEN (16) +#endif +#ifdef ARM64 +#define MAX_HEXADDR_STRLEN (16) +#define UVADDR_PRLEN (10) +#endif + +#define BADADDR ((ulong)(-1)) +#define BADVAL ((ulong)(-1)) +#define UNUSED (-1) + +#define UNINITIALIZED (BADVAL) + +#define BITS_PER_BYTE (8) +#define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long)) +#define NUM_TO_BIT(x) (1UL<<((x)%BITS_PER_LONG)) +#define NUM_IN_BITMAP(bitmap, x) (bitmap[(x)/BITS_PER_LONG] & NUM_TO_BIT(x)) +#define SET_BIT(bitmap, x) (bitmap[(x)/BITS_PER_LONG] |= NUM_TO_BIT(x)) + +/* + * precision lengths for fprintf + */ +#define VADDR_PRLEN (sizeof(char *) == 8 ? 16 : 8) +#define LONG_LONG_PRLEN (16) +#define LONG_PRLEN (sizeof(long) == 8 ? 16 : 8) +#define INT_PRLEN (sizeof(int) == 8 ? 16 : 8) +#define CHAR_PRLEN (2) +#define SHORT_PRLEN (4) + +#define MINSPACE (-100) + +#define SYNOPSIS (0x1) +#define COMPLETE_HELP (0x2) +#define PIPE_TO_SCROLL (0x4) +#define MUST_HELP (0x8) + +#define LEFT_JUSTIFY (1) +#define RIGHT_JUSTIFY (2) + +#define CENTER (0x1) +#define LJUST (0x2) +#define RJUST (0x4) +#define LONG_DEC (0x8) +#define LONG_HEX (0x10) +#define INT_DEC (0x20) +#define INT_HEX (0x40) +#define LONGLONG_HEX (0x80) +#define ZERO_FILL (0x100) + +#define INIT_TIME (1) +#define RUN_TIME (2) + +/* + * IRQ line status. + * For kernels up to and including 2.6.17 + */ +#define IRQ_INPROGRESS_2_6_17 1 /* IRQ handler active - do not enter! */ +#define IRQ_DISABLED_2_6_17 2 /* IRQ disabled - do not enter! */ +#define IRQ_PENDING_2_6_17 4 /* IRQ pending - replay on enable */ +#define IRQ_REPLAY_2_6_17 8 /* IRQ has been replayed but not acked yet */ +#define IRQ_AUTODETECT_2_6_17 16 /* IRQ is being autodetected */ +#define IRQ_WAITING_2_6_17 32 /* IRQ not yet seen - for autodetection */ +#define IRQ_LEVEL_2_6_17 64 /* IRQ level triggered */ +#define IRQ_MASKED_2_6_17 128 /* IRQ masked - shouldn't be seen again */ + +/* + * For kernel 2.6.21 and later + */ +#define IRQ_TYPE_NONE_2_6_21 0x00000000 /* Default, unspecified type */ +#define IRQ_TYPE_EDGE_RISING_2_6_21 0x00000001 /* Edge rising type */ +#define IRQ_TYPE_EDGE_FALLING_2_6_21 0x00000002 /* Edge falling type */ +#define IRQ_TYPE_EDGE_BOTH_2_6_21 (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING) +#define IRQ_TYPE_LEVEL_HIGH_2_6_21 0x00000004 /* Level high type */ +#define IRQ_TYPE_LEVEL_LOW_2_6_21 0x00000008 /* Level low type */ +#define IRQ_TYPE_SENSE_MASK_2_6_21 0x0000000f /* Mask of the above */ +#define IRQ_TYPE_PROBE_2_6_21 0x00000010 /* Probing in progress */ + +#define IRQ_INPROGRESS_2_6_21 0x00000100 /* IRQ handler active - do not enter! */ +#define IRQ_DISABLED_2_6_21 0x00000200 /* IRQ disabled - do not enter! */ +#define IRQ_PENDING_2_6_21 0x00000400 /* IRQ pending - replay on enable */ +#define IRQ_REPLAY_2_6_21 0x00000800 /* IRQ has been replayed but not acked yet */ +#define IRQ_AUTODETECT_2_6_21 0x00001000 /* IRQ is being autodetected */ +#define IRQ_WAITING_2_6_21 0x00002000 /* IRQ not yet seen - for autodetection */ +#define IRQ_LEVEL_2_6_21 0x00004000 /* IRQ level triggered */ +#define IRQ_MASKED_2_6_21 0x00008000 /* IRQ masked - shouldn't be seen again */ +#define IRQ_PER_CPU_2_6_21 0x00010000 /* IRQ is per CPU */ +#define IRQ_NOPROBE_2_6_21 0x00020000 /* IRQ is not valid for probing */ +#define IRQ_NOREQUEST_2_6_21 0x00040000 /* IRQ cannot be requested */ +#define IRQ_NOAUTOEN_2_6_21 0x00080000 /* IRQ will not be enabled on request irq */ +#define IRQ_WAKEUP_2_6_21 0x00100000 /* IRQ triggers system wakeup */ +#define IRQ_MOVE_PENDING_2_6_21 0x00200000 /* need to re-target IRQ destination */ +#define IRQ_NO_BALANCING_2_6_21 0x00400000 /* IRQ is excluded from balancing */ +#define IRQ_SPURIOUS_DISABLED_2_6_21 0x00800000 /* IRQ was disabled by the spurious trap */ +#define IRQ_MOVE_PCNTXT_2_6_21 0x01000000 /* IRQ migration from process context */ +#define IRQ_AFFINITY_SET_2_6_21 0x02000000 /* IRQ affinity was set from userspace*/ + +/* + * Select proper IRQ value depending on kernel version + */ +#define IRQ_TYPE_NONE \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_NONE_2_6_21 : 0) +#define IRQ_TYPE_EDGE_RISING \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_EDGE_RISING_2_6_21 : 0) +#define IRQ_TYPE_EDGE_FALLING \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_EDGE_FALLING_2_6_21 : 0) +#define IRQ_TYPE_EDGE_BOTH \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_EDGE_BOTH_2_6_21 : 0) +#define IRQ_TYPE_LEVEL_HIGH \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_LEVEL_HIGH_2_6_21 : 0) +#define IRQ_TYPE_LEVEL_LOW \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_LEVEL_LOW_2_6_21 : 0) +#define IRQ_TYPE_SENSE_MASK \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_SENSE_MASK_2_6_21 : 0) +#define IRQ_TYPE_PROBE \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_TYPE_PROBE_2_6_21 : 0) + +#define IRQ_INPROGRESS \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_INPROGRESS_2_6_21 : IRQ_INPROGRESS_2_6_17) +#define IRQ_DISABLED \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_DISABLED_2_6_21 : IRQ_DISABLED_2_6_17) +#define IRQ_PENDING \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_PENDING_2_6_21 : IRQ_PENDING_2_6_17) +#define IRQ_REPLAY \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_REPLAY_2_6_21 : IRQ_REPLAY_2_6_17) +#define IRQ_AUTODETECT \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_AUTODETECT_2_6_21 : IRQ_AUTODETECT_2_6_17) +#define IRQ_WAITING \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_WAITING_2_6_21 : IRQ_WAITING_2_6_17) +#define IRQ_LEVEL \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_LEVEL_2_6_21 : IRQ_LEVEL_2_6_17) +#define IRQ_MASKED \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_MASKED_2_6_21 : IRQ_MASKED_2_6_17) +#define IRQ_PER_CPU \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_PER_CPU_2_6_21 : 0) +#define IRQ_NOPROBE \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_NOPROBE_2_6_21 : 0) +#define IRQ_NOREQUEST \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_NOREQUEST_2_6_21 : 0) +#define IRQ_NOAUTOEN \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_NOAUTOEN_2_6_21 : 0) +#define IRQ_WAKEUP \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_WAKEUP_2_6_21 : 0) +#define IRQ_MOVE_PENDING \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_MOVE_PENDING_2_6_21 : 0) +#define IRQ_NO_BALANCING \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_NO_BALANCING_2_6_21 : 0) +#define IRQ_SPURIOUS_DISABLED \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_SPURIOUS_DISABLED_2_6_21 : 0) +#define IRQ_MOVE_PCNTXT \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_MOVE_PCNTXT_2_6_21 : 0) +#define IRQ_AFFINITY_SET \ + (THIS_KERNEL_VERSION >= LINUX(2,6,21) ? IRQ_AFFINITY_SET_2_6_21 : 0) + +#ifdef ARM +#define SA_PROBE SA_ONESHOT +#define SA_SAMPLE_RANDOM SA_RESTART +#define SA_SHIRQ 0x04000000 +#define SA_RESTORER 0x04000000 +#endif + +#ifdef X86 +#define SA_PROBE SA_ONESHOT +#define SA_SAMPLE_RANDOM SA_RESTART +#define SA_SHIRQ 0x04000000 +#define SA_RESTORER 0x04000000 +#endif + +#ifdef X86_64 +#define SA_PROBE SA_ONESHOT +#define SA_SAMPLE_RANDOM SA_RESTART +#define SA_SHIRQ 0x04000000 +#define SA_RESTORER 0x04000000 +#endif + +#ifdef ALPHA +#define SA_PROBE SA_ONESHOT +#define SA_SAMPLE_RANDOM SA_RESTART +#define SA_SHIRQ 0x40000000 +#endif + +#ifdef PPC +#define SA_PROBE SA_ONESHOT +#define SA_SAMPLE_RANDOM SA_RESTART +#define SA_SHIRQ 0x04000000 +#define SA_RESTORER 0x04000000 +#endif + +#ifdef PPC64 +#define SA_PROBE SA_ONESHOT +#define SA_SAMPLE_RANDOM SA_RESTART +#define SA_SHIRQ 0x04000000 +#define SA_RESTORER 0x04000000u +#endif + +#ifdef IA64 +#define SA_PROBE SA_ONESHOT +#define SA_SAMPLE_RANDOM SA_RESTART +#define SA_SHIRQ 0x04000000 +#define SA_RESTORER 0x04000000 +#endif + +#ifdef S390 +#define SA_PROBE SA_ONESHOT +#define SA_SAMPLE_RANDOM SA_RESTART +#define SA_SHIRQ 0x04000000 +#define SA_RESTORER 0x04000000 +#endif + +#ifdef S390X +#define SA_PROBE SA_ONESHOT +#define SA_SAMPLE_RANDOM SA_RESTART +#define SA_SHIRQ 0x04000000 +#define SA_RESTORER 0x04000000 +#endif + + +#define ACTION_FLAGS (SA_INTERRUPT|SA_PROBE|SA_SAMPLE_RANDOM|SA_SHIRQ) + + +#endif /* !GDB_COMMON */ + +/* + * Common request structure for BFD or GDB data or commands. + */ +struct gnu_request { + int command; + char *buf; + FILE *fp; + ulong addr; + ulong addr2; + ulong count; + ulong flags; + char *name; + ulong length; + int typecode; +#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) || defined(GDB_7_0) + char *typename; +#else + char *type_name; +#endif + char *target_typename; + ulong target_length; + int target_typecode; + int is_typedef; + char *member; + long member_offset; + long member_length; + int member_typecode; + long value; + char *tagname; + ulong pc; + ulong sp; + ulong ra; + int curframe; + ulong frame; + ulong prevsp; + ulong prevpc; + ulong lastsp; + ulong task; + ulong debug; + struct stack_hook *hookp; +}; + +/* + * GNU commands + */ +#define GNU_DATATYPE_INIT (1) +#define GNU_DISASSEMBLE (2) +#define GNU_GET_LINE_NUMBER (3) +#define GNU_PASS_THROUGH (4) +#define GNU_GET_DATATYPE (5) +#define GNU_COMMAND_EXISTS (6) +#define GNU_STACK_TRACE (7) +#define GNU_ALPHA_FRAME_OFFSET (8) +#define GNU_FUNCTION_NUMARGS (9) +#define GNU_RESOLVE_TEXT_ADDR (10) +#define GNU_ADD_SYMBOL_FILE (11) +#define GNU_DELETE_SYMBOL_FILE (12) +#define GNU_VERSION (13) +#define GNU_PATCH_SYMBOL_VALUES (14) +#define GNU_GET_SYMBOL_TYPE (15) +#define GNU_USER_PRINT_OPTION (16) +#define GNU_SET_CRASH_BLOCK (17) +#define GNU_DEBUG_COMMAND (100) +/* + * GNU flags + */ +#define GNU_PRINT_LINE_NUMBERS (0x1) +#define GNU_FUNCTION_ONLY (0x2) +#define GNU_PRINT_ENUMERATORS (0x4) +#define GNU_RETURN_ON_ERROR (0x8) +#define GNU_COMMAND_FAILED (0x10) +#define GNU_FROM_TTY_OFF (0x20) +#define GNU_NO_READMEM (0x40) +#define GNU_VAR_LENGTH_TYPECODE (0x80) + +#undef TRUE +#undef FALSE + +#define TRUE (1) +#define FALSE (0) + +#ifdef GDB_COMMON +/* + * function prototypes required by modified gdb source files. + */ +int console(char *, ...); +int gdb_CRASHDEBUG(ulong); +int gdb_readmem_callback(ulong, void *, int, int); +void patch_load_module(struct objfile *objfile, struct minimal_symbol *msymbol); +int patch_kernel_symbol(struct gnu_request *); +struct syment *symbol_search(char *); +int gdb_line_number_callback(ulong, ulong, ulong); +int gdb_print_callback(ulong); +#endif + +#ifndef GDB_COMMON +/* + * WARNING: the following type codes are type_code enums from gdb/gdbtypes.h + */ +enum type_code { + TYPE_CODE_UNDEF, /* Not used; catches errors */ + TYPE_CODE_PTR, /* Pointer type */ + TYPE_CODE_ARRAY, /* Array type with lower & upper bounds. */ + TYPE_CODE_STRUCT, /* C struct or Pascal record */ + TYPE_CODE_UNION, /* C union or Pascal variant part */ + TYPE_CODE_ENUM, /* Enumeration type */ +#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) || defined(GDB_7_0) || defined(GDB_7_3_1) || defined(GDB_7_6) +#if defined(GDB_7_0) || defined(GDB_7_3_1) || defined(GDB_7_6) + TYPE_CODE_FLAGS, /* Bit flags type */ +#endif + TYPE_CODE_FUNC, /* Function type */ + TYPE_CODE_INT, /* Integer type */ + + /* Floating type. This is *NOT* a complex type. Beware, there are parts + of GDB which bogusly assume that TYPE_CODE_FLT can mean complex. */ + TYPE_CODE_FLT, + + /* Void type. The length field specifies the length (probably always + one) which is used in pointer arithmetic involving pointers to + this type, but actually dereferencing such a pointer is invalid; + a void type has no length and no actual representation in memory + or registers. A pointer to a void type is a generic pointer. */ + TYPE_CODE_VOID, + + TYPE_CODE_SET, /* Pascal sets */ + TYPE_CODE_RANGE, /* Range (integers within spec'd bounds) */ + + /* + * NOTE: the remainder of the type codes are not list or used here... + */ +#endif +}; + +#define PF_EXITING 0x00000004 /* getting shut down */ + +extern long _ZOMBIE_; +#define IS_ZOMBIE(task) (task_state(task) & _ZOMBIE_) +#define IS_EXITING(task) (task_flags(task) & PF_EXITING) + +/* + * ps command options. + */ +#define PS_BY_PID (0x1) +#define PS_BY_TASK (0x2) +#define PS_BY_CMD (0x4) +#define PS_SHOW_ALL (0x8) +#define PS_PPID_LIST (0x10) +#define PS_CHILD_LIST (0x20) +#define PS_KERNEL (0x40) +#define PS_USER (0x80) +#define PS_TIMES (0x100) +#define PS_KSTACKP (0x200) +#define PS_LAST_RUN (0x400) +#define PS_ARGV_ENVP (0x800) +#define PS_TGID_LIST (0x1000) +#define PS_RLIMIT (0x2000) +#define PS_GROUP (0x4000) +#define PS_BY_REGEX (0x8000) +#define PS_NO_HEADER (0x10000) + +#define PS_EXCLUSIVE (PS_TGID_LIST|PS_ARGV_ENVP|PS_TIMES|PS_CHILD_LIST|PS_PPID_LIST|PS_LAST_RUN|PS_RLIMIT) + +#define MAX_PS_ARGS (100) /* maximum command-line specific requests */ + +struct psinfo { + int argc; + ulong pid[MAX_PS_ARGS]; + int type[MAX_PS_ARGS]; + ulong task[MAX_PS_ARGS]; + char comm[MAX_PS_ARGS][TASK_COMM_LEN+1]; + struct regex_data { + char *pattern; + regex_t regex; + } regex_data[MAX_PS_ARGS]; + int regexs; +}; + +#define IS_A_NUMBER(X) (decimal(X, 0) || hexadecimal(X, 0)) +#define AMBIGUOUS_NUMBER(X) (decimal(X, 0) && hexadecimal(X, 0)) + +#define is_mclx_compressed_dump(X) (va_server_init((X), 0, 0, 0) == 0) + +struct task_mem_usage { + ulong rss; + ulong total_vm; + double pct_physmem; + ulong mm_struct_addr; + ulong pgd_addr; +}; + +/* + * Global data (global_data.c) + */ +extern FILE *fp; +extern struct program_context program_context, *pc; +extern struct task_table task_table, *tt; +extern struct kernel_table kernel_table, *kt; +extern struct command_table_entry linux_command_table[]; +extern char *args[MAXARGS]; +extern int argcnt; +extern int argerrs; +extern struct offset_table offset_table; +extern struct size_table size_table; +extern struct array_table array_table; +extern struct vm_table vm_table, *vt; +extern struct machdep_table *machdep; +extern struct symbol_table_data symbol_table_data, *st; +extern struct extension_table *extension_table; + +/* + * Generated in build_data.c + */ +extern char *build_command; +extern char *build_data; +extern char *build_target; +extern char *build_version; +extern char *compiler_version; + + +/* + * command prototypes + */ +void cmd_quit(void); /* main.c */ +void cmd_mach(void); /* main.c */ +void cmd_help(void); /* help.c */ +void cmd_test(void); /* test.c */ +void cmd_ascii(void); /* tools.c */ +void cmd_set(void); /* tools.c */ +void cmd_eval(void); /* tools.c */ +void cmd_list(void); /* tools.c */ +void cmd_tree(void); /* tools.c */ +void cmd_template(void); /* tools.c */ +void cmd_alias(void); /* cmdline.c */ +void cmd_repeat(void); /* cmdline.c */ +void cmd_rd(void); /* memory.c */ +void cmd_wr(void); /* memory.c */ +void cmd_ptov(void); /* memory.c */ +void cmd_vtop(void); /* memory.c */ +void cmd_vm(void); /* memory.c */ +void cmd_ptob(void); /* memory.c */ +void cmd_btop(void); /* memory.c */ +void cmd_kmem(void); /* memory.c */ +void cmd_search(void); /* memory.c */ +void cmd_swap(void); /* memory.c */ +void cmd_pte(void); /* memory.c */ +void cmd_ps(void); /* task.c */ +void cmd_task(void); /* task.c */ +void cmd_foreach(void); /* task.c */ +void cmd_runq(void); /* task.c */ +void cmd_sig(void); /* task.c */ +void cmd_bt(void); /* kernel.c */ +void cmd_dis(void); /* kernel.c */ +void cmd_mod(void); /* kernel.c */ +void cmd_log(void); /* kernel.c */ +void cmd_sys(void); /* kernel.c */ +void cmd_irq(void); /* kernel.c */ +void cmd_timer(void); /* kernel.c */ +void cmd_waitq(void); /* kernel.c */ +void cmd_sym(void); /* symbols.c */ +void cmd_struct(void); /* symbols.c */ +void cmd_union(void); /* symbols.c */ +void cmd_pointer(void); /* symbols.c */ +void cmd_whatis(void); /* symbols.c */ +void cmd_p(void); /* symbols.c */ +void cmd_mount(void); /* filesys.c */ +void cmd_files(void); /* filesys.c */ +void cmd_fuser(void); /* filesys.c */ +void cmd_dev(void); /* dev.c */ +void cmd_gdb(void); /* gdb_interface.c */ +void cmd_net(void); /* net.c */ +void cmd_extend(void); /* extensions.c */ +#if defined(S390) || defined(S390X) +void cmd_s390dbf(void); +#endif +void cmd_map(void); /* kvmdump.c */ +void cmd_ipcs(void); /* ipcs.c */ + +/* + * main.c + */ +void main_loop(void); +void exec_command(void); +struct command_table_entry *get_command_table_entry(char *); +void program_usage(int); +#define LONG_FORM (1) +#define SHORT_FORM (0) +void dump_program_context(void); +void dump_build_data(void); +#ifdef ARM +#define machdep_init(X) arm_init(X) +#endif +#ifdef ARM64 +#define machdep_init(X) arm64_init(X) +#endif +#ifdef X86 +#define machdep_init(X) x86_init(X) +#endif +#ifdef ALPHA +#define machdep_init(X) alpha_init(X) +#endif +#ifdef PPC +#define machdep_init(X) ppc_init(X) +#endif +#ifdef IA64 +#define machdep_init(X) ia64_init(X) +#endif +#ifdef S390 +#define machdep_init(X) s390_init(X) +#endif +#ifdef S390X +#define machdep_init(X) s390x_init(X) +#endif +#ifdef X86_64 +#define machdep_init(X) x86_64_init(X) +#endif +#ifdef PPC64 +#define machdep_init(X) ppc64_init(X) +#endif +int clean_exit(int); +int untrusted_file(FILE *, char *); +char *readmem_function_name(void); +char *writemem_function_name(void); + +/* + * cmdline.c + */ +void restart(int); +void alias_init(char *); +struct alias_data *is_alias(char *); +void deallocate_alias(char *); +void cmdline_init(void); +void set_command_prompt(char *); +void exec_input_file(void); +void process_command_line(void); +void dump_history(void); +void resolve_rc_cmd(char *, int); +void dump_alias_data(void); +int output_open(void); +#define output_closed() (!output_open()) +void close_output(void); +int interruptible(void); +int received_SIGINT(void); +void debug_redirect(char *); +int CRASHPAGER_valid(void); +char *setup_scroll_command(void); +int minimal_functions(char *); +int is_args_input_file(struct command_table_entry *, struct args_input_file *); +void exec_args_input_file(struct command_table_entry *, struct args_input_file *); + +/* + * tools.c + */ +int __error(int, char *, ...); +#define error __error /* avoid conflict with gdb error() */ +int console(char *, ...); +void create_console_device(char *); +int console_off(void); +int console_on(int); +int console_verbatim(char *); +int whitespace(int); +int ascii(int); +int ascii_string(char *); +char *clean_line(char *); +char *strip_line_end(char *); +char *strip_linefeeds(char *); +char *strip_beginning_whitespace(char *); +char *strip_ending_whitespace(char *); +char *strip_ending_char(char *, char); +char *strip_beginning_char(char *, char); +char *strip_comma(char *); +char *strip_hex(char *); +char *upper_case(char *, char *); +char *first_nonspace(char *); +char *first_space(char *); +char *replace_string(char *, char *, char); +void string_insert(char *, char *); +char *strstr_rightmost(char *, char *); +char *null_first_space(char *); +int parse_line(char *, char **); +void print_verbatim(FILE *, char *); +char *fixup_percent(char *); +int can_eval(char *); +ulong eval(char *, int, int *); +ulonglong evall(char *, int, int *); +int eval_common(char *, int, int *, struct number_option *); +ulong htol(char *, int, int *); +ulong dtol(char *, int, int *); +unsigned int dtoi(char *, int, int *); +ulong stol(char *, int, int *); +ulonglong stoll(char *, int, int *); +ulonglong htoll(char *, int, int *); +ulonglong dtoll(char *, int, int *); +int decimal(char *, int); +int hexadecimal(char *, int); +int hexadecimal_only(char *, int); +ulong convert(char *, int, int *, ulong); +void pad_line(FILE *, int, char); +#define INDENT(x) pad_line(fp, x, ' ') +char *mkstring(char *, int, ulong, const char *); +#define MKSTR(X) ((const char *)(X)) +int count_leading_spaces(char *); +int count_chars(char *, char); +long count_buffer_chars(char *, char, long); +char *space(int); +char *concat_args(char *, int, int); +char *shift_string_left(char *, int); +char *shift_string_right(char *, int); +int bracketed(char *, char *, int); +void backspace(int); +int do_list(struct list_data *); +int do_rdtree(struct tree_data *); +int do_rbtree(struct tree_data *); +int retrieve_list(ulong *, int); +long power(long, int); +long long ll_power(long long, long long); +void hq_init(void); +int hq_open(void); +int hq_close(void); +int hq_enter(ulong); +int hq_entry_exists(ulong); +int hq_is_open(void); +int hq_is_inuse(void); +long get_embedded(void); +void dump_embedded(char *); +char *ordinal(ulong, char *); +char *first_nonspace(char *); +void dump_hash_table(int); +void dump_shared_bufs(void); +void drop_core(char *); +int extract_hex(char *, ulong *, char, ulong); +int count_bits_int(int); +int count_bits_long(ulong); +int highest_bit_long(ulong); +int lowest_bit_long(ulong); +void buf_init(void); +void sym_buf_init(void); +void free_all_bufs(void); +char *getbuf(long); +void freebuf(char *); +char *resizebuf(char *, long, long); +#define GETBUF(X) getbuf((long)(X)) +#define FREEBUF(X) freebuf((char *)(X)) +#define RESIZEBUF(X,Y,Z) (X) = resizebuf((char *)(X), (long)(Y), (long)(Z)); +void sigsetup(int, void *, struct sigaction *, struct sigaction *); +#define SIGACTION(s, h, a, o) sigsetup(s, h, a, o) +char *convert_time(ulonglong, char *); +void stall(ulong); +char *pages_to_size(ulong, char *); +int clean_arg(void); +int empty_list(ulong); +int machine_type(char *); +int machine_type_mismatch(char *, char *, char *, ulong); +void command_not_supported(void); +void option_not_supported(int); +void please_wait(char *); +void please_wait_done(void); +int pathcmp(char *, char *); +int calculate(char *, ulong *, ulonglong *, ulong); +int endian_mismatch(char *, char, ulong); +uint16_t swap16(uint16_t, int); +uint32_t swap32(uint32_t, int); +ulong *get_cpumask_buf(void); +int make_cpumask(char *, ulong *, int, int *); +size_t strlcpy(char *, char *, size_t); +struct rb_node *rb_first(struct rb_root *); +struct rb_node *rb_parent(struct rb_node *, struct rb_node *); +struct rb_node *rb_right(struct rb_node *, struct rb_node *); +struct rb_node *rb_left(struct rb_node *, struct rb_node *); +struct rb_node *rb_next(struct rb_node *); +struct rb_node *rb_last(struct rb_root *); + +/* + * symbols.c + */ +void symtab_init(void); +char *check_specified_kernel_debug_file(void); +void no_debugging_data(int); +void get_text_init_space(void); +int is_kernel_text(ulong); +int is_kernel_data(ulong); +int is_init_data(ulong value); +int is_kernel_text_offset(ulong); +int is_rodata(ulong, struct syment **); +void datatype_init(void); +struct syment *symbol_search(char *); +struct syment *value_search(ulong, ulong *); +struct syment *value_search_base_kernel(ulong, ulong *); +struct syment *value_search_module(ulong, ulong *); +struct syment *symbol_search_next(char *, struct syment *); +ulong highest_bss_symbol(void); +int in_ksymbol_range(ulong); +int module_symbol(ulong, struct syment **, + struct load_module **, char *, ulong); +#define IS_MODULE_VADDR(X) \ + (module_symbol((ulong)(X), NULL, NULL, NULL, *gdb_output_radix)) +char *closest_symbol(ulong); +ulong closest_symbol_value(ulong); +#define SAME_FUNCTION(X,Y) (closest_symbol_value(X) == closest_symbol_value(Y)) +void show_symbol(struct syment *, ulong, ulong); +#define SHOW_LINENUM (0x1) +#define SHOW_SECTION (0x2) +#define SHOW_HEX_OFFS (0x4) +#define SHOW_DEC_OFFS (0x8) +#define SHOW_RADIX() (*gdb_output_radix == 16 ? SHOW_HEX_OFFS : SHOW_DEC_OFFS) +#define SHOW_MODULE (0x10) +int symbol_query(char *, char *, struct syment **); +struct syment *next_symbol(char *, struct syment *); +struct syment *prev_symbol(char *, struct syment *); +void get_symbol_data(char *, long, void *); +int try_get_symbol_data(char *, long, void *); +char *value_to_symstr(ulong, char *, ulong); +char *value_symbol(ulong); +ulong symbol_value(char *); +ulong symbol_value_module(char *, char *); +struct syment *per_cpu_symbol_search(char *); +int symbol_exists(char *s); +int kernel_symbol_exists(char *s); +struct syment *kernel_symbol_search(char *); +int get_syment_array(char *, struct syment **, int); +void set_temporary_radix(unsigned int, unsigned int *); +void restore_current_radix(unsigned int); +void dump_struct(char *, ulong, unsigned); +void dump_struct_member(char *, ulong, unsigned); +void dump_union(char *, ulong, unsigned); +void store_module_symbols_v1(ulong, int); +void store_module_symbols_v2(ulong, int); +int is_datatype_command(void); +int is_typedef(char *); +int arg_to_datatype(char *, struct datatype_member *, ulong); +void dump_symbol_table(void); +void dump_struct_table(ulong); +void dump_offset_table(char *, ulong); +int is_elf_file(char *); +int is_kernel(char *); +int is_shared_object(char *); +int file_elf_version(char *); +int is_system_map(char *); +int is_compressed_kernel(char *, char **); +int select_namelist(char *); +int get_array_length(char *, int *, long); +int get_array_length_alt(char *, char *, int *, long); +int builtin_array_length(char *, int, int *); +char *get_line_number(ulong, char *, int); +char *get_build_directory(char *); +int datatype_exists(char *); +int get_function_numargs(ulong); +int is_module_name(char *, ulong *, struct load_module **); +int is_module_address(ulong, char *); +ulong lowest_module_address(void); +ulong highest_module_address(void); +int load_module_symbols(char *, char *, ulong); +void delete_load_module(ulong); +ulong gdb_load_module_callback(ulong, char *); +char *load_module_filter(char *, int); +#define LM_P_FILTER (1) +#define LM_DIS_FILTER (2) +long datatype_info(char *, char *, struct datatype_member *); +int get_symbol_type(char *, char *, struct gnu_request *); +int get_symbol_length(char *); +int text_value_cache(ulong, uint32_t, uint32_t *); +int text_value_cache_byte(ulong, unsigned char *); +void dump_text_value_cache(int); +void clear_text_value_cache(void); +void dump_numargs_cache(void); +int patch_kernel_symbol(struct gnu_request *); +struct syment *generic_machdep_value_to_symbol(ulong, ulong *); +long OFFSET_verify(long, char *, char *, int, char *); +long SIZE_verify(long, char *, char *, int, char *); +long OFFSET_option(long, long, char *, char *, int, char *, char *); +long SIZE_option(long, long, char *, char *, int, char *, char *); +void dump_trace(void **); +int enumerator_value(char *, long *); +int dump_enumerator_list(char *); +struct load_module *init_module_function(ulong); + +/* + * memory.c + */ +void mem_init(void); +void vm_init(void); +int readmem(ulonglong, int, void *, long, char *, ulong); +int writemem(ulonglong, int, void *, long, char *, ulong); +int generic_verify_paddr(uint64_t); +int read_dev_mem(int, void *, int, ulong, physaddr_t); +int read_memory_device(int, void *, int, ulong, physaddr_t); +int read_mclx_dumpfile(int, void *, int, ulong, physaddr_t); +int read_lkcd_dumpfile(int, void *, int, ulong, physaddr_t); +int read_daemon(int, void *, int, ulong, physaddr_t); +int write_dev_mem(int, void *, int, ulong, physaddr_t); +int write_memory_device(int, void *, int, ulong, physaddr_t); +int write_mclx_dumpfile(int, void *, int, ulong, physaddr_t); +int write_lkcd_dumpfile(int, void *, int, ulong, physaddr_t); +int write_daemon(int, void *, int, ulong, physaddr_t); +int kvtop(struct task_context *, ulong, physaddr_t *, int); +int uvtop(struct task_context *, ulong, physaddr_t *, int); +void do_vtop(ulong, struct task_context *, ulong); +void raw_stack_dump(ulong, ulong); +void raw_data_dump(ulong, long, int); +int accessible(ulong); +ulong vm_area_dump(ulong, ulong, ulong, struct reference *); +#define IN_TASK_VMA(TASK,VA) (vm_area_dump((TASK), UVADDR|VERIFY_ADDR, (VA), 0)) +char *fill_vma_cache(ulong); +void clear_vma_cache(void); +void dump_vma_cache(ulong); +int is_page_ptr(ulong, physaddr_t *); +void dump_vm_table(int); +int read_string(ulong, char *, int); +void get_task_mem_usage(ulong, struct task_mem_usage *); +char *get_memory_size(char *); +uint64_t generic_memory_size(void); +char *swap_location(ulonglong, char *); +void clear_swap_info_cache(void); +uint memory_page_size(void); +void force_page_size(char *); +ulong first_vmalloc_address(void); +ulong last_vmalloc_address(void); +int in_vmlist_segment(ulong); +int phys_to_page(physaddr_t, ulong *); +int generic_get_kvaddr_ranges(struct vaddr_range *); +int l1_cache_size(void); +int dumpfile_memory(int); +#define DUMPFILE_MEM_USED (1) +#define DUMPFILE_FREE_MEM (2) +#define DUMPFILE_MEM_DUMP (3) +#define DUMPFILE_ENVIRONMENT (4) +uint64_t total_node_memory(void); +int generic_is_kvaddr(ulong); +int generic_is_uvaddr(ulong, struct task_context *); +void fill_stackbuf(struct bt_info *); +void alter_stackbuf(struct bt_info *); +int vaddr_type(ulong, struct task_context *); +char *format_stack_entry(struct bt_info *bt, char *, ulong, ulong); +int in_user_stack(ulong, ulong); + +/* + * filesys.c + */ +void fd_init(void); +void vfs_init(void); +int is_a_tty(char *); +int file_exists(char *, struct stat *); +int file_readable(char *); +int is_directory(char *); +char *search_directory_tree(char *, char *, int); +void open_tmpfile(void); +void close_tmpfile(void); +void open_tmpfile2(void); +void set_tmpfile2(FILE *); +void close_tmpfile2(void); +void open_files_dump(ulong, int, struct reference *); +void get_pathname(ulong, char *, int, int, ulong); +char *vfsmount_devname(ulong, char *, int); +ulong file_to_dentry(ulong); +ulong file_to_vfsmnt(ulong); +int get_proc_version(void); +int file_checksum(char *, long *); +void dump_filesys_table(int); +char *fill_file_cache(ulong); +void clear_file_cache(void); +char *fill_dentry_cache(ulong); +void clear_dentry_cache(void); +char *fill_inode_cache(ulong); +void clear_inode_cache(void); +int monitor_memory(long *, long *, long *, long *); +int is_readable(char *); +#define RADIX_TREE_COUNT (1) +#define RADIX_TREE_SEARCH (2) +#define RADIX_TREE_DUMP (3) +#define RADIX_TREE_GATHER (4) +struct radix_tree_pair { + ulong index; + void *value; +}; +ulong do_radix_tree(ulong, int, struct radix_tree_pair *); +int file_dump(ulong, ulong, ulong, int, int); +#define DUMP_FULL_NAME 1 +#define DUMP_INODE_ONLY 2 +#define DUMP_DENTRY_ONLY 4 +#define DUMP_EMPTY_FILE 8 +#endif /* !GDB_COMMON */ +int same_file(char *, char *); +#ifndef GDB_COMMON +int cleanup_memory_driver(void); + + +/* + * help.c + */ +#define HELP_COLUMNS 5 +#define START_OF_HELP_DATA(X) "START_OF_HELP_DATA" X +#define END_OF_HELP_DATA "END_OF_HELP_DATA" +void help_init(void); +void cmd_usage(char *, int); +void display_version(void); +void display_help_screen(char *); +#ifdef ARM +#define dump_machdep_table(X) arm_dump_machdep_table(X) +#endif +#ifdef ARM64 +#define dump_machdep_table(X) arm64_dump_machdep_table(X) +#endif +#ifdef X86 +#define dump_machdep_table(X) x86_dump_machdep_table(X) +#endif +#ifdef ALPHA +#define dump_machdep_table(X) alpha_dump_machdep_table(X) +#endif +#ifdef PPC +#define dump_machdep_table(X) ppc_dump_machdep_table(X) +#endif +#ifdef IA64 +#define dump_machdep_table(X) ia64_dump_machdep_table(X) +#endif +#ifdef S390 +#define dump_machdep_table(X) s390_dump_machdep_table(X) +#endif +#ifdef S390X +#define dump_machdep_table(X) s390x_dump_machdep_table(X) +#endif +#ifdef X86_64 +#define dump_machdep_table(X) x86_64_dump_machdep_table(X) +#endif +#ifdef PPC64 +#define dump_machdep_table(X) ppc64_dump_machdep_table(X) +#endif +extern char *help_pointer[]; +extern char *help_alias[]; +extern char *help_ascii[]; +extern char *help_bt[]; +extern char *help_btop[]; +extern char *help_dev[]; +extern char *help_dis[]; +extern char *help_eval[]; +extern char *help_exit[]; +extern char *help_extend[]; +extern char *help_files[]; +extern char *help_foreach[]; +extern char *help_fuser[]; +extern char *help_gdb[]; +extern char *help_help[]; +extern char *help_irq[]; +extern char *help_kmem[]; +extern char *help__list[]; +extern char *help_tree[]; +extern char *help_log[]; +extern char *help_mach[]; +extern char *help_mod[]; +extern char *help_mount[]; +extern char *help_net[]; +extern char *help_p[]; +extern char *help_ps[]; +extern char *help_pte[]; +extern char *help_ptob[]; +extern char *help_ptov[]; +extern char *help_quit[]; +extern char *help_rd[]; +extern char *help_repeat[]; +extern char *help_runq[]; +extern char *help_ipcs[]; +extern char *help_search[]; +extern char *help_set[]; +extern char *help_sig[]; +extern char *help_struct[]; +extern char *help_swap[]; +extern char *help_sym[]; +extern char *help_sys[]; +extern char *help_task[]; +extern char *help_timer[]; +extern char *help_union[]; +extern char *help_vm[]; +extern char *help_vtop[]; +extern char *help_waitq[]; +extern char *help_whatis[]; +extern char *help_wr[]; +#if defined(S390) || defined(S390X) +extern char *help_s390dbf[]; +#endif +extern char *help_map[]; + +/* + * task.c + */ +void task_init(void); +int set_context(ulong, ulong); +void show_context(struct task_context *); +ulong pid_to_task(ulong); +ulong task_to_pid(ulong); +int task_exists(ulong); +int is_kernel_thread(ulong); +int is_idle_thread(ulong); +void get_idle_threads(ulong *, int); +char *task_state_string(ulong, char *, int); +ulong task_flags(ulong); +ulong task_state(ulong); +ulong task_mm(ulong, int); +ulong task_tgid(ulong); +ulonglong task_last_run(ulong); +ulong vaddr_in_task_struct(ulong); +int comm_exists(char *); +struct task_context *task_to_context(ulong); +struct task_context *pid_to_context(ulong); +struct task_context *tgid_to_context(ulong); +ulong stkptr_to_task(ulong); +ulong task_to_thread_info(ulong); +ulong task_to_stackbase(ulong); +int str_to_context(char *, ulong *, struct task_context **); +#define STR_PID (0x1) +#define STR_TASK (0x2) +#define STR_INVALID (0x4) +char *get_panicmsg(char *); +char *task_cpu(int, char *, int); +void print_task_header(FILE *, struct task_context *, int); +ulong get_active_task(int); +int is_task_active(ulong); +int is_panic_thread(ulong); +int get_panic_ksp(struct bt_info *, ulong *); +void foreach(struct foreach_data *); +int pid_exists(ulong); +#define TASKS_PER_PID(x) pid_exists(x) +char *fill_task_struct(ulong); +#define IS_LAST_TASK_READ(task) ((ulong)(task) == tt->last_task_read) +char *fill_thread_info(ulong); +#define IS_LAST_THREAD_INFO_READ(ti) ((ulong)(ti) == tt->last_thread_info_read) +char *fill_mm_struct(ulong); +#define IS_LAST_MM_READ(mm) ((ulong)(mm) == tt->last_mm_read) +void do_task(ulong, ulong, struct reference *, unsigned int); +void clear_task_cache(void); +int get_active_set(void); +void clear_active_set(void); +void do_sig(ulong, ulong, struct reference *); +void modify_signame(int, char *, char *); +ulong generic_get_stackbase(ulong); +ulong generic_get_stacktop(ulong); +void dump_task_table(int); +void sort_context_array(void); +int in_irq_ctx(ulonglong, int, ulong); + +/* + * extensions.c + */ +void register_extension(struct command_table_entry *); +void dump_extension_table(int); +void load_extension(char *); +void unload_extension(char *); +void preload_extensions(void); +/* Hooks for sial */ +unsigned long get_curtask(void); +char *crash_global_cmd(void); +struct command_table_entry *crash_cmd_table(void); + +/* + * kernel.c + */ +void kernel_init(void); +void module_init(void); +void verify_version(void); +void verify_spinlock(void); +void non_matching_kernel(void); +struct load_module *modref_to_load_module(char *); +int load_module_symbols_helper(char *); +void unlink_module(struct load_module *); +int check_specified_module_tree(char *, char *); +int is_system_call(char *, ulong); +void generic_dump_irq(int); +void generic_get_irq_affinity(int); +void generic_show_interrupts(int, ulong *); +int generic_dis_filter(ulong, char *, unsigned int); +int kernel_BUG_encoding_bytes(void); +void display_sys_stats(void); +char *get_uptime(char *, ulonglong *); +void clone_bt_info(struct bt_info *, struct bt_info *, struct task_context *); +void dump_kernel_table(int); +void dump_bt_info(struct bt_info *, char *where); +void dump_log(int); +#define SHOW_LOG_LEVEL (0x1) +#define SHOW_LOG_DICT (0x2) +#define SHOW_LOG_TEXT (0x4) +void set_cpu(int); +void clear_machdep_cache(void); +struct stack_hook *gather_text_list(struct bt_info *); +int get_cpus_online(void); +int get_cpus_present(void); +int get_cpus_possible(void); +int get_highest_cpu_online(void); +int get_highest_cpu_present(void); +int get_cpus_to_display(void); +void get_log_from_vmcoreinfo(char *file, char *(*)(const char *)); +int in_cpu_map(int, int); +void paravirt_init(void); +void print_stack_text_syms(struct bt_info *, ulong, ulong); +void back_trace(struct bt_info *); +int in_alternate_stack(int, ulong); +ulong cpu_map_addr(const char *type); +#define BT_RAW (0x1ULL) +#define BT_SYMBOLIC_ARGS (0x2ULL) +#define BT_FULL (0x4ULL) +#define BT_TEXT_SYMBOLS (0x8ULL) +#define BT_TEXT_SYMBOLS_PRINT (0x10ULL) +#define BT_TEXT_SYMBOLS_NOPRINT (0x20ULL) +#define BT_USE_GDB (0x40ULL) +#define BT_EXCEPTION_FRAME (0x80ULL) +#define BT_LINE_NUMBERS (0x100ULL) +#define BT_USER_EFRAME (0x200ULL) +#define BT_INCOMPLETE_USER_EFRAME (BT_USER_EFRAME) +#define BT_SAVE_LASTSP (0x400ULL) +#define BT_FROM_EXCEPTION (0x800ULL) +#define BT_FROM_CALLFRAME (0x1000ULL) +#define BT_EFRAME_SEARCH (0x2000ULL) +#define BT_SPECULATE (0x4000ULL) +#define BT_FRAMESIZE_DISABLE (BT_SPECULATE) +#define BT_RESCHEDULE (0x8000ULL) +#define BT_SCHEDULE (BT_RESCHEDULE) +#define BT_RET_FROM_SMP_FORK (0x10000ULL) +#define BT_STRACE (0x20000ULL) +#define BT_KSTACKP (0x40000ULL) +#define BT_LOOP_TRAP (0x80000ULL) +#define BT_BUMP_FRAME_LEVEL (0x100000ULL) +#define BT_EFRAME_COUNT (0x200000ULL) +#define BT_CPU_IDLE (0x400000ULL) +#define BT_WRAP_TRAP (0x800000ULL) +#define BT_KERNEL_THREAD (0x1000000ULL) +#define BT_ERROR_MASK (BT_LOOP_TRAP|BT_WRAP_TRAP|BT_KERNEL_THREAD|BT_CPU_IDLE) +#define BT_UNWIND_ERROR (0x2000000ULL) +#define BT_OLD_BACK_TRACE (0x4000000ULL) +#define BT_FRAMESIZE_DEBUG (0x8000000ULL) +#define BT_CONTEXT_SWITCH (0x10000000ULL) +#define BT_HARDIRQ (0x20000000ULL) +#define BT_SOFTIRQ (0x40000000ULL) +#define BT_CHECK_CALLER (0x80000000ULL) +#define BT_NO_CHECK_CALLER (0x100000000ULL) +#define BT_EXCEPTION_STACK (0x200000000ULL) +#define BT_IRQSTACK (0x400000000ULL) +#define BT_DUMPFILE_SEARCH (0x800000000ULL) +#define BT_EFRAME_SEARCH2 (0x1000000000ULL) +#define BT_START (0x2000000000ULL) +#define BT_TEXT_SYMBOLS_ALL (0x4000000000ULL) +#define BT_XEN_STOP_THIS_CPU (0x8000000000ULL) +#define BT_THREAD_GROUP (0x10000000000ULL) +#define BT_SAVE_EFRAME_IP (0x20000000000ULL) +#define BT_FULL_SYM_SLAB (0x40000000000ULL) +#define BT_KDUMP_ELF_REGS (0x80000000000ULL) +#define BT_USER_SPACE (0x100000000000ULL) +#define BT_KERNEL_SPACE (0x200000000000ULL) +#define BT_SYMBOL_OFFSET (BT_SYMBOLIC_ARGS) + +#define BT_REF_HEXVAL (0x1) +#define BT_REF_SYMBOL (0x2) +#define BT_REF_FOUND (0x4) +#define BT_REFERENCE_CHECK(X) ((X)->ref) +#define BT_REFERENCE_FOUND(X) ((X)->ref && ((X)->ref->cmdflags & BT_REF_FOUND)) + +#define NO_MODULES() \ + (!kt->module_list || (kt->module_list == kt->kernel_module)) + +#define USER_EFRAME_ADDR(task) \ + ((ulong)task + UNION_SIZE("task_union") - SIZE(pt_regs)) + +struct remote_file { + char *filename; + char *local; + int fd; + int flags; + int type; + long csum; + off_t size; +}; + +#define REMOTE_VERBOSE (O_RDWR << 1) +#define REMOTE_COPY_DONE (REMOTE_VERBOSE << 1) +#define TYPE_ELF (REMOTE_VERBOSE << 2) +#define TYPE_DEVMEM (REMOTE_VERBOSE << 3) +#define TYPE_MCLXCD (REMOTE_VERBOSE << 4) +#define TYPE_LKCD (REMOTE_VERBOSE << 5) +#define TYPE_S390D (REMOTE_VERBOSE << 6) +#define TYPE_NETDUMP (REMOTE_VERBOSE << 7) + +ulonglong xen_m2p(ulonglong); + +void read_in_kernel_config(int); + +#define IKCFG_INIT (0) +#define IKCFG_READ (1) +#define IKCFG_SETUP (2) +#define IKCFG_FREE (3) + +int get_kernel_config(char *, char **); +enum { + IKCONFIG_N, + IKCONFIG_Y, + IKCONFIG_M, + IKCONFIG_STR, +}; + +#define MAGIC_START "IKCFG_ST" +#define MAGIC_END "IKCFG_ED" +#define MAGIC_SIZE (sizeof(MAGIC_START) - 1) + +/* + * dev.c + */ +void dev_init(void); +void dump_dev_table(void); + +#ifdef ARM +void arm_init(int); +void arm_dump_machdep_table(ulong); +int arm_is_vmalloc_addr(ulong); +void arm_dump_backtrace_entry(struct bt_info *, int, ulong, ulong); + +#define display_idt_table() \ + error(FATAL, "-d option is not applicable to ARM architecture\n") + +struct arm_pt_regs { + ulong uregs[18]; +}; + +#define ARM_cpsr uregs[16] +#define ARM_pc uregs[15] +#define ARM_lr uregs[14] +#define ARM_sp uregs[13] +#define ARM_ip uregs[12] +#define ARM_fp uregs[11] +#define ARM_r10 uregs[10] +#define ARM_r9 uregs[9] +#define ARM_r8 uregs[8] +#define ARM_r7 uregs[7] +#define ARM_r6 uregs[6] +#define ARM_r5 uregs[5] +#define ARM_r4 uregs[4] +#define ARM_r3 uregs[3] +#define ARM_r2 uregs[2] +#define ARM_r1 uregs[1] +#define ARM_r0 uregs[0] +#define ARM_ORIG_r0 uregs[17] + +#define KSYMS_START (0x1) +#define PHYS_BASE (0x2) +#define PGTABLE_V2 (0x4) +#define IDMAP_PGD (0x8) + +#define KVBASE_MASK (0x1ffffff) + +struct machine_specific { + ulong phys_base; + ulong vmalloc_start_addr; + ulong modules_vaddr; + ulong modules_end; + ulong kernel_text_start; + ulong kernel_text_end; + ulong exception_text_start; + ulong exception_text_end; + struct arm_pt_regs *crash_task_regs; + int unwind_index_prel31; +}; + +int init_unwind_tables(void); +void unwind_backtrace(struct bt_info *); +#endif /* ARM */ + +/* + * arm64.c + */ +#ifdef ARM64 +void arm64_init(int); +void arm64_dump_machdep_table(ulong); +int arm64_IS_VMALLOC_ADDR(ulong); +#endif + +/* + * alpha.c + */ +#ifdef ALPHA +void alpha_init(int); +void alpha_dump_machdep_table(ulong); +#define display_idt_table() \ + error(FATAL, "-d option is not applicable to alpha architecture\n") + +#define HWRESET_TASK(X) ((machdep->flags & HWRESET) && is_task_active(X) && \ + (task_to_context(X)->processor == 0)) +#endif + +/* + * x86.c + */ +#ifdef X86 +void x86_init(int); +void x86_dump_machdep_table(ulong); +void x86_display_idt_table(void); +#define display_idt_table() x86_display_idt_table() +#define KSYMS_START (0x1) +void x86_dump_eframe_common(struct bt_info *bt, ulong *, int); +char *x86_function_called_by(ulong); +struct syment *x86_jmp_error_code(ulong); +struct syment *x86_text_lock_jmp(ulong, ulong *); + +struct machine_specific { + ulong *idt_table; + ulong entry_tramp_start; + ulong entry_tramp_end; + physaddr_t entry_tramp_start_phys; + ulonglong last_pmd_read_PAE; + ulonglong last_ptbl_read_PAE; + ulong page_protnone; + int max_numnodes; + ulong *remap_start_vaddr; + ulong *remap_end_vaddr; + ulong *remap_start_pfn; +}; + +struct syment *x86_is_entry_tramp_address(ulong, ulong *); +#endif + +/* + * x86_64.c + */ +#ifdef X86_64 +void x86_64_init(int); +void x86_64_dump_machdep_table(ulong); +ulong x86_64_PTOV(ulong); +ulong x86_64_VTOP(ulong); +int x86_64_IS_VMALLOC_ADDR(ulong); +void x86_64_display_idt_table(void); +#define display_idt_table() x86_64_display_idt_table() +long x86_64_exception_frame(ulong, ulong, char *, struct bt_info *, FILE *); +#define EFRAME_INIT (0) + +struct x86_64_pt_regs_offsets { + long r15; + long r14; + long r13; + long r12; + long rbp; + long rbx; +/* arguments: non interrupts/non tracing syscalls only save upto here*/ + long r11; + long r10; + long r9; + long r8; + long rax; + long rcx; + long rdx; + long rsi; + long rdi; + long orig_rax; +/* end of arguments */ +/* cpu exception frame or undefined */ + long rip; + long cs; + long eflags; + long rsp; + long ss; +}; + +#define MAX_EXCEPTION_STACKS 7 +#define NMI_STACK 2 /* ebase[] index to NMI exception stack */ +#define DEBUG_STACK 3 /* ebase[] index to DEBUG exception stack */ + +struct x86_64_stkinfo { + ulong ebase[NR_CPUS][MAX_EXCEPTION_STACKS]; + int esize[MAX_EXCEPTION_STACKS]; + ulong ibase[NR_CPUS]; + int isize; +}; + +struct machine_specific { + ulong userspace_top; + ulong page_offset; + ulong vmalloc_start_addr; + ulong vmalloc_end; + ulong vmemmap_vaddr; + ulong vmemmap_end; + ulong modules_vaddr; + ulong modules_end; + ulong phys_base; + char *pml4; + char *upml; + ulong last_upml_read; + ulong last_pml4_read; + char *irqstack; + ulong irq_eframe_link; + struct x86_64_pt_regs_offsets pto; + struct x86_64_stkinfo stkinfo; + ulong *current; + ulong *crash_nmi_rsp; + ulong vsyscall_page; + ulong thread_return; + ulong page_protnone; + ulong GART_start; + ulong GART_end; +}; + +#define KSYMS_START (0x1) +#define PT_REGS_INIT (0x2) +#define VM_ORIG (0x4) +#define VM_2_6_11 (0x8) +#define VM_XEN (0x10) +#define NO_TSS (0x20) +#define SCHED_TEXT (0x40) +#define PHYS_BASE (0x80) +#define VM_XEN_RHEL4 (0x100) +#define FRAMEPOINTER (0x200) +#define GART_REGION (0x400) + +#define VM_FLAGS (VM_ORIG|VM_2_6_11|VM_XEN|VM_XEN_RHEL4) + +#define _2MB_PAGE_MASK (~((MEGABYTES(2))-1)) + +#endif + +#if defined(X86) || defined(X86_64) + +/* + * unwind_x86_32_64.c + */ +void init_unwind_table(void); +int dwarf_backtrace(struct bt_info *, int, ulong); +void dwarf_debug(struct bt_info *); +int dwarf_print_stack_entry(struct bt_info *, int); + +#endif + + +/* + * ppc64.c + */ +#ifdef PPC64 +/* + * This structure was copied from kernel source + * in include/asm-ppc/ptrace.h + */ +struct ppc64_pt_regs { + long gpr[32]; + long nip; + long msr; + long orig_gpr3; /* Used for restarting system calls */ + long ctr; + long link; + long xer; + long ccr; + long mq; /* 601 only (not used at present) */ + /* Used on APUS to hold IPL value. */ + long trap; /* Reason for being here */ + long dar; /* Fault registers */ + long dsisr; + long result; /* Result of a system call */ +}; + +struct ppc64_vmemmap { + unsigned long phys; + unsigned long virt; +}; + +/* + * Used to store the HW interrupt stack. It is only for 2.4. + */ +struct machine_specific { + ulong hwintrstack[NR_CPUS]; + char *hwstackbuf; + uint hwstacksize; + char *level4; + ulong last_level4_read; + + uint l4_index_size; + uint l3_index_size; + uint l2_index_size; + uint l1_index_size; + + uint ptrs_per_l3; + uint ptrs_per_l2; + uint ptrs_per_l1; + + uint l4_shift; + uint l3_shift; + uint l2_shift; + uint l1_shift; + + uint pte_shift; + uint l2_masked_bits; + + int vmemmap_cnt; + int vmemmap_psize; + ulong vmemmap_base; + struct ppc64_vmemmap *vmemmap_list; + ulong _page_present; + ulong _page_user; + ulong _page_rw; + ulong _page_guarded; + ulong _page_coherent; + ulong _page_no_cache; + ulong _page_writethru; + ulong _page_dirty; + ulong _page_accessed; + int (*is_kvaddr)(ulong); + int (*is_vmaddr)(ulong); +}; + +#define IS_LAST_L4_READ(l4) ((ulong)(l4) == machdep->machspec->last_level4_read) + +#define FILL_L4(L4, TYPE, SIZE) \ + if (!IS_LAST_L4_READ(L4)) { \ + readmem((ulonglong)((ulong)(L4)), TYPE, machdep->machspec->level4, \ + SIZE, "level4 page", FAULT_ON_ERROR); \ + machdep->machspec->last_level4_read = (ulong)(L4); \ + } + +void ppc64_init(int); +void ppc64_dump_machdep_table(ulong); +#define display_idt_table() \ + error(FATAL, "-d option is not applicable to PowerPC architecture\n") +#define KSYMS_START (0x1) +#define VM_ORIG (0x2) +#define VMEMMAP_AWARE (0x4) +#define BOOK3E (0x8) + +#define REGION_SHIFT (60UL) +#define REGION_ID(addr) (((unsigned long)(addr)) >> REGION_SHIFT) +#define VMEMMAP_REGION_ID (0xfUL) +#endif + +/* + * ppc.c + */ +#ifdef PPC +void ppc_init(int); +void ppc_dump_machdep_table(ulong); +void ppc_relocate_nt_prstatus_percpu(void **, uint *); +#define display_idt_table() \ + error(FATAL, "-d option is not applicable to PowerPC architecture\n") +#define KSYMS_START (0x1) +/* This should match PPC_FEATURE_BOOKE from include/asm-powerpc/cputable.h */ +#define CPU_BOOKE (0x00008000) +#else +#define ppc_relocate_nt_prstatus_percpu(X,Y) do {} while (0) +#endif + +/* + * lkcd_fix_mem.c + */ + +struct _dump_header_asm_s; +struct _dump_header_s; +ulong get_lkcd_switch_stack(ulong); +int fix_addr_v8(struct _dump_header_asm_s *); +int lkcd_dump_init_v8_arch(struct _dump_header_s *dh); +int fix_addr_v7(int); +int get_lkcd_regs_for_cpu_arch(int cpu, ulong *eip, ulong *esp); +int lkcd_get_kernel_start_v8(ulong *addr); + +/* + * lkcd_v8.c + */ +int get_lkcd_regs_for_cpu_v8(struct bt_info *bt, ulong *eip, ulong *esp); + +/* + * ia64.c + */ +#ifdef IA64 +void ia64_init(int); +void ia64_dump_machdep_table(ulong); +void ia64_dump_line_number(ulong); +ulong ia64_get_switch_stack(ulong); +void ia64_exception_frame(ulong, struct bt_info *bt); +ulong ia64_PTOV(ulong); +ulong ia64_VTOP(ulong); +int ia64_IS_VMALLOC_ADDR(ulong); +#define display_idt_table() \ + error(FATAL, "-d option TBD on ia64 architecture\n"); +int ia64_in_init_stack(ulong addr); +int ia64_in_mca_stack_hyper(ulong addr, struct bt_info *bt); +physaddr_t ia64_xen_kdump_p2m(struct xen_kdump_data *xkd, physaddr_t pseudo); + +#define OLD_UNWIND (0x1) /* CONFIG_IA64_NEW_UNWIND not turned on */ +#define NEW_UNWIND (0x2) /* CONFIG_IA64_NEW_UNWIND turned on */ +#define NEW_UNW_V1 (0x4) +#define NEW_UNW_V2 (0x8) +#define NEW_UNW_V3 (0x10) +#define UNW_OUT_OF_SYNC (0x20) /* shared data structures out of sync */ +#define UNW_READ (0x40) /* kernel unw has been read successfully */ +#define MEM_LIMIT (0x80) +#define UNW_PTREGS (0x100) +#define UNW_R0 (0x200) + +#undef IA64_RBS_OFFSET +#undef IA64_STK_OFFSET +#define IA64_RBS_OFFSET ((SIZE(task_struct) + 15) & ~15) +#define IA64_STK_OFFSET (STACKSIZE()) + +struct machine_specific { + ulong cpu_data_address; + ulong unimpl_va_mask; + ulong unimpl_pa_mask; + long unw_tables_offset; + long unw_kernel_table_offset; + long unw_pt_regs_offsets; + int script_index; + struct unw_script *script_cache; + ulong script_cache_fills; + ulong script_cache_hits; + void *unw; + ulong mem_limit; + ulong kernel_region; + ulong kernel_start; + ulong phys_start; + ulong vmalloc_start; + char *ia64_memmap; + uint64_t efi_memmap_size; + uint64_t efi_memdesc_size; + void (*unwind_init)(void); + void (*unwind)(struct bt_info *); + void (*dump_unwind_stats)(void); + int (*unwind_debug)(ulong); + int ia64_init_stack_size; +}; + + +/* + * unwind.c + */ +void unwind_init_v1(void); +void unwind_v1(struct bt_info *); +void dump_unwind_stats_v1(void); +int unwind_debug_v1(ulong); + +void unwind_init_v2(void); +void unwind_v2(struct bt_info *); +void dump_unwind_stats_v2(void); +int unwind_debug_v2(ulong); + +void unwind_init_v3(void); +void unwind_v3(struct bt_info *); +void dump_unwind_stats_v3(void); +int unwind_debug_v3(ulong); + +#endif /* IA64 */ + +/* + * s390.c + */ +#ifdef S390 +void s390_init(int); +void s390_dump_machdep_table(ulong); +#define display_idt_table() \ + error(FATAL, "-d option is not applicable to S390 architecture\n") +#define KSYMS_START (0x1) +#endif + +/* + * s390_dump.c + */ +int is_s390_dump(char *); +FILE* s390_dump_init(char *); +int read_s390_dumpfile(int, void *, int, ulong, physaddr_t); +int write_s390_dumpfile(int, void *, int, ulong, physaddr_t); +uint s390_page_size(void); +int s390_memory_used(void); +int s390_free_memory(void); +int s390_memory_dump(FILE *); +ulong get_s390_panic_task(void); +void get_s390_panicmsg(char *); + +/* + * s390x.c + */ +#ifdef S390X +void s390x_init(int); +void s390x_dump_machdep_table(ulong); +#define display_idt_table() \ + error(FATAL, "-d option is not applicable to S390X architecture\n") +#define KSYMS_START (0x1) +#endif + +/* + * netdump.c + */ +int is_netdump(char *, ulong); +uint netdump_page_size(void); +int read_netdump(int, void *, int, ulong, physaddr_t); +int write_netdump(int, void *, int, ulong, physaddr_t); +int netdump_free_memory(void); +int netdump_memory_used(void); +int netdump_init(char *, FILE *); +ulong get_netdump_panic_task(void); +ulong get_netdump_switch_stack(ulong); +FILE *set_netdump_fp(FILE *); +int netdump_memory_dump(FILE *); +void get_netdump_regs(struct bt_info *, ulong *, ulong *); +int is_partial_netdump(void); +void get_netdump_regs_x86(struct bt_info *, ulong *, ulong *); +void get_netdump_regs_x86_64(struct bt_info *, ulong *, ulong *); +void dump_registers_for_elf_dumpfiles(void); +struct vmcore_data; +struct vmcore_data *get_kdump_vmcore_data(void); +int read_kdump(int, void *, int, ulong, physaddr_t); +int write_kdump(int, void *, int, ulong, physaddr_t); +int is_kdump(char *, ulong); +int kdump_init(char *, FILE *); +ulong get_kdump_panic_task(void); +uint kdump_page_size(void); +int kdump_free_memory(void); +int kdump_memory_used(void); +int kdump_memory_dump(FILE *); +void get_kdump_regs(struct bt_info *, ulong *, ulong *); +void xen_kdump_p2m_mfn(char *); +int is_sadump_xen(void); +void set_xen_phys_start(char *); +ulong xen_phys_start(void); +int xen_major_version(void); +int xen_minor_version(void); +int get_netdump_arch(void); +int exist_regs_in_elf_notes(struct task_context *); +void *get_regs_from_elf_notes(struct task_context *); +void map_cpus_to_prstatus(void); +int arm_kdump_phys_base(ulong *); +int is_proc_kcore(char *, ulong); +int proc_kcore_init(FILE *); +int read_proc_kcore(int, void *, int, ulong, physaddr_t); +int write_proc_kcore(int, void *, int, ulong, physaddr_t); +int kcore_memory_dump(FILE *); +void dump_registers_for_qemu_mem_dump(void); +void kdump_backup_region_init(void); + +/* + * diskdump.c + */ +int is_diskdump(char *); +uint diskdump_page_size(void); +int read_diskdump(int, void *, int, ulong, physaddr_t); +int write_diskdump(int, void *, int, ulong, physaddr_t); +int diskdump_free_memory(void); +int diskdump_memory_used(void); +int diskdump_init(char *, FILE *); +ulong get_diskdump_panic_task(void); +ulong get_diskdump_switch_stack(ulong); +int diskdump_memory_dump(FILE *); +FILE *set_diskdump_fp(FILE *); +void get_diskdump_regs(struct bt_info *, ulong *, ulong *); +int diskdump_phys_base(unsigned long *); +ulong *diskdump_flags; +int is_partial_diskdump(void); +int dumpfile_is_split(void); +void show_split_dumpfiles(void); +void x86_process_elf_notes(void *, unsigned long); +void *diskdump_get_prstatus_percpu(int); +void map_cpus_to_prstatus_kdump_cmprs(void); +void diskdump_display_regs(int, FILE *); +void process_elf32_notes(void *, ulong); +void process_elf64_notes(void *, ulong); +void dump_registers_for_compressed_kdump(void); + +/* + * makedumpfile.c + */ +void check_flattened_format(char *file); +int is_flattened_format(char *file); +int read_flattened_format(int fd, off_t offset, void *buf, size_t size); +void dump_flat_header(FILE *); + +/* + * xendump.c + */ +int is_xendump(char *); +int read_xendump(int, void *, int, ulong, physaddr_t); +int write_xendump(int, void *, int, ulong, physaddr_t); +uint xendump_page_size(void); +int xendump_free_memory(void); +int xendump_memory_used(void); +int xendump_init(char *, FILE *); +int xendump_memory_dump(FILE *); +ulong get_xendump_panic_task(void); +void get_xendump_regs(struct bt_info *, ulong *, ulong *); +char *xc_core_mfn_to_page(ulong, char *); +int xc_core_mfn_to_page_index(ulong); +void xendump_panic_hook(char *); +int read_xendump_hyper(int, void *, int, ulong, physaddr_t); +struct xendump_data *get_xendump_data(void); + +/* + * kvmdump.c + */ +int is_kvmdump(char *); +int is_kvmdump_mapfile(char *); +int kvmdump_init(char *, FILE *); +int read_kvmdump(int, void *, int, ulong, physaddr_t); +int write_kvmdump(int, void *, int, ulong, physaddr_t); +int kvmdump_free_memory(void); +int kvmdump_memory_used(void); +int kvmdump_memory_dump(FILE *); +void get_kvmdump_regs(struct bt_info *, ulong *, ulong *); +ulong get_kvmdump_panic_task(void); +int kvmdump_phys_base(unsigned long *); +void kvmdump_display_regs(int, FILE *); +void set_kvmhost_type(char *); +void set_kvm_iohole(char *); +struct kvm_register_set { + union { + uint32_t cs; + uint32_t ss; + uint32_t ds; + uint32_t es; + uint32_t fs; + uint32_t gs; + uint64_t ip; + uint64_t flags; + uint64_t regs[16]; + } x86; +}; +int get_kvm_register_set(int, struct kvm_register_set *); + +/* + * sadump.c + */ +int is_sadump(char *); +uint sadump_page_size(void); +int read_sadump(int, void *, int, ulong, physaddr_t); +int write_sadump(int, void *, int, ulong, physaddr_t); +int sadump_init(char *, FILE *); +int sadump_is_diskset(void); +ulong get_sadump_panic_task(void); +ulong get_sadump_switch_stack(ulong); +int sadump_memory_used(void); +int sadump_free_memory(void); +int sadump_memory_dump(FILE *); +FILE *set_sadump_fp(FILE *); +void get_sadump_regs(struct bt_info *bt, ulong *ipp, ulong *spp); +void sadump_display_regs(int, FILE *); +int sadump_phys_base(ulong *); +void sadump_show_diskset(void); +int sadump_is_zero_excluded(void); +void sadump_set_zero_excluded(void); +void sadump_unset_zero_excluded(void); +struct sadump_data; +struct sadump_data *get_sadump_data(void); + +/* + * qemu.c + */ +int qemu_init(char *); + +/* + * qemu-load.c + */ +int is_qemu_vm_file(char *); +void dump_qemu_header(FILE *); + +/* + * net.c + */ +void net_init(void); +void dump_net_table(void); +void dump_sockets_workhorse(ulong, ulong, struct reference *); + +/* + * remote.c + */ +int is_remote_daemon(char *); +physaddr_t get_remote_phys_base(physaddr_t, physaddr_t); +physaddr_t remote_vtop(int, physaddr_t); +int get_remote_regs(struct bt_info *, ulong *, ulong *); +physaddr_t get_remote_cr3(int); +void remote_fd_init(void); +int get_remote_file(struct remote_file *); +uint remote_page_size(void); +int find_remote_module_objfile(struct load_module *lm, char *, char *); +int remote_free_memory(void); +int remote_memory_dump(int); +int remote_memory_used(void); +void remote_exit(void); +int remote_execute(void); +void remote_clear_pipeline(void); +int remote_memory_read(int, char *, int, physaddr_t, int); + +/* + * gnu_binutils.c + */ + +/* NO LONGER IN USE */ + +/* + * test.c + */ +void cmd_template(void); +void foreach_test(ulong, ulong); + +/* + * va_server.c + */ +int mclx_page_size(void); +int vas_memory_used(void); +int vas_memory_dump(FILE *); +int vas_free_memory(char *); +void set_vas_debug(ulong); +size_t vas_write(void *, size_t); +int va_server_init(char *, ulong *, ulong *, ulong *); +size_t vas_read(void *, size_t); +int vas_lseek(ulong, int); + +/* + * lkcd_x86_trace.c + */ +int lkcd_x86_back_trace(struct bt_info *, int, FILE *); + +/* + * lkcd_common.c + */ +int lkcd_dump_init(FILE *, int, char *); +ulong get_lkcd_panic_task(void); +void get_lkcd_panicmsg(char *); +int is_lkcd_compressed_dump(char *); +void dump_lkcd_environment(ulong); +int lkcd_lseek(physaddr_t); +long lkcd_read(void *, long); +void set_lkcd_debug(ulong); +FILE *set_lkcd_fp(FILE *); +uint lkcd_page_size(void); +int lkcd_memory_used(void); +int lkcd_memory_dump(FILE *); +int lkcd_free_memory(void); +void lkcd_print(char *, ...); +void set_remote_lkcd_panic_data(ulong, char *); +void set_lkcd_nohash(void); +int lkcd_load_dump_page_header(void *, ulong); +void lkcd_dumpfile_complaint(uint32_t, uint32_t, int); +int set_mb_benchmark(ulong); +ulonglong fix_lkcd_address(ulonglong); +int lkcd_get_kernel_start(ulong *addr); +int get_lkcd_regs_for_cpu(struct bt_info *bt, ulong *eip, ulong *esp); + +/* + * lkcd_v1.c + */ +int lkcd_dump_init_v1(FILE *, int); +void dump_dump_page_v1(char *, void *); +void dump_lkcd_environment_v1(ulong); +uint32_t get_dp_size_v1(void); +uint32_t get_dp_flags_v1(void); +uint64_t get_dp_address_v1(void); + +/* + * lkcd_v2_v3.c + */ +int lkcd_dump_init_v2_v3(FILE *, int); +void dump_dump_page_v2_v3(char *, void *); +void dump_lkcd_environment_v2_v3(ulong); +uint32_t get_dp_size_v2_v3(void); +uint32_t get_dp_flags_v2_v3(void); +uint64_t get_dp_address_v2_v3(void); + +/* + * lkcd_v5.c + */ +int lkcd_dump_init_v5(FILE *, int); +void dump_dump_page_v5(char *, void *); +void dump_lkcd_environment_v5(ulong); +uint32_t get_dp_size_v5(void); +uint32_t get_dp_flags_v5(void); +uint64_t get_dp_address_v5(void); + +/* + * lkcd_v7.c + */ +int lkcd_dump_init_v7(FILE *, int, char *); +void dump_dump_page_v7(char *, void *); +void dump_lkcd_environment_v7(ulong); +uint32_t get_dp_size_v7(void); +uint32_t get_dp_flags_v7(void); +uint64_t get_dp_address_v7(void); + +/* + * lkcd_v8.c + */ +int lkcd_dump_init_v8(FILE *, int, char *); +void dump_dump_page_v8(char *, void *); +void dump_lkcd_environment_v8(ulong); +uint32_t get_dp_size_v8(void); +uint32_t get_dp_flags_v8(void); +uint64_t get_dp_address_v8(void); + +#ifdef LKCD_COMMON +/* + * Until they differ across versions, these remain usable in the common + * routines in lkcd_common.c + */ +#define LKCD_DUMP_MAGIC_NUMBER (0xa8190173618f23edULL) +#define LKCD_DUMP_MAGIC_LIVE (0xa8190173618f23cdULL) + +#define LKCD_DUMP_V1 (0x1) /* DUMP_VERSION_NUMBER */ +#define LKCD_DUMP_V2 (0x2) /* DUMP_VERSION_NUMBER */ +#define LKCD_DUMP_V3 (0x3) /* DUMP_VERSION_NUMBER */ +#define LKCD_DUMP_V5 (0x5) /* DUMP_VERSION_NUMBER */ +#define LKCD_DUMP_V6 (0x6) /* DUMP_VERSION_NUMBER */ +#define LKCD_DUMP_V7 (0x7) /* DUMP_VERSION_NUMBER */ +#define LKCD_DUMP_V8 (0x8) /* DUMP_VERSION_NUMBER */ +#define LKCD_DUMP_V9 (0x9) /* DUMP_VERSION_NUMBER */ +#define LKCD_DUMP_V10 (0xa) /* DUMP_VERSION_NUMBER */ + +#define LKCD_DUMP_VERSION_NUMBER_MASK (0xf) +#define LKCD_DUMP_RAW (0x1) /* DUMP_[DH_]RAW */ +#define LKCD_DUMP_COMPRESSED (0x2) /* DUMP_[DH_]COMPRESSED */ +#define LKCD_DUMP_END (0x4) /* DUMP_[DH_]END */ + +#define LKCD_DUMP_COMPRESS_NONE (0x0) /* DUMP_COMPRESS_NONE */ +#define LKCD_DUMP_COMPRESS_RLE (0x1) /* DUMP_COMPRESS_RLE */ +#define LKCD_DUMP_COMPRESS_GZIP (0x2) /* DUMP_COMPRESS_GZIP */ + +#define LKCD_DUMP_MCLX_V0 (0x80000000) /* MCLX mod of LKCD */ +#define LKCD_DUMP_MCLX_V1 (0x40000000) /* Extra page header data */ +#define LKCD_OFFSET_TO_FIRST_PAGE (65536) + +#define MCLX_PAGE_HEADERS (4096) +#define MCLX_V1_PAGE_HEADER_CACHE ((sizeof(uint64_t)) * MCLX_PAGE_HEADERS) + +/* + * lkcd_load_dump_page_header() return values + */ +#define LKCD_DUMPFILE_OK (0) +#define LKCD_DUMPFILE_EOF (1) +#define LKCD_DUMPFILE_END (2) + +/* + * Common handling of LKCD dump environment + */ +#define LKCD_CACHED_PAGES (16) +#define LKCD_PAGE_HASH (32) +#define LKCD_DUMP_HEADER_ONLY (1) /* arguments to lkcd_dump_environment */ +#define LKCD_DUMP_PAGE_ONLY (2) + +#define LKCD_VALID (0x1) /* flags */ +#define LKCD_REMOTE (0x2) +#define LKCD_NOHASH (0x4) +#define LKCD_MCLX (0x8) +#define LKCD_BAD_DUMP (0x10) + +struct page_hash_entry { + uint32_t pg_flags; + uint64_t pg_addr; + off_t pg_hdr_offset; + struct page_hash_entry *next; +}; + +struct page_desc { + off_t offset; /* lseek offset in dump file */ +}; + +struct physmem_zone { + uint64_t start; + struct page_desc *pages; +}; + +struct fix_addrs { + ulong task; + ulong saddr; + ulong sw; +}; + + +struct lkcd_environment { + int fd; /* dumpfile file descriptor */ + ulong flags; /* flags from above */ + ulong debug; /* shadow of pc->debug */ + FILE *fp; /* abstracted fp for fprintf */ + void *dump_header; /* header stash, v1 or v2 */ + void *dump_header_asm; /* architecture specific header for v2 */ + void *dump_header_asm_smp; /* architecture specific header for v7 & v8 */ + void *dump_page; /* current page header holder */ + uint32_t version; /* version number of this dump */ + uint32_t page_size; /* size of a Linux memory page */ + int page_shift; /* byte address to page */ + int bits; /* processor bitsize */ + ulong panic_task; /* panic task address */ + char *panic_string; /* pointer to stashed panic string */ + uint32_t compression; /* compression type */ + uint32_t (*get_dp_size)(void); /* returns current page's dp_size */ + uint32_t (*get_dp_flags)(void); /* returns current page's dp_size */ + uint64_t (*get_dp_address)(void); /* returns current page's dp_address*/ + size_t page_header_size; /* size of version's page header */ + unsigned long curpos; /* offset into current page */ + uint64_t curpaddr; /* current page's physical address */ + off_t curhdroffs; /* current page's header offset */ + char *curbufptr; /* pointer to uncompressed page buffer */ + uint64_t kvbase; /* physical-to-LKCD page address format*/ + char *page_cache_buf; /* base of cached buffer pages */ + char *compressed_page; /* copy of compressed page data */ + int evict_index; /* next page to evict */ + ulong evictions; /* total evictions done */ + struct page_cache_hdr { /* header for each cached page */ + uint32_t pg_flags; + uint64_t pg_addr; + char *pg_bufptr; + ulong pg_hit_count; + } page_cache_hdr[LKCD_CACHED_PAGES]; + struct page_hash_entry *page_hash; + ulong total_pages; + ulong benchmark_pages; + ulong benchmarks_done; + off_t *mb_hdr_offsets; + ulong total_reads; + ulong cached_reads; + ulong hashed_reads; + ulong hashed; + ulong compressed; + ulong raw; + + /* lkcd_v7 additions */ + char *dumpfile_index; /* array of offsets for each page */ + int ifd; /* index file for dump (LKCD V7+) */ + long memory_pages; /* Mamimum index of dump pages */ + off_t page_offset_max; /* Offset of page with greatest offset seen so far */ + long page_index_max; /* Index of page with greatest offset seen so far */ + off_t *page_offsets; /* Pointer to huge array with seek offsets */ + /* NB: There are no holes in the array */ + + struct physmem_zone *zones; /* Array of physical memory zones */ + int num_zones; /* Number of zones initialized */ + int max_zones; /* Size of the zones array */ + long zoned_offsets; /* Number of stored page offsets */ + uint64_t zone_mask; + int zone_shift; + + int fix_addr_num; /* Number of active stacks to switch to saved values */ + struct fix_addrs *fix_addr; /* Array of active stacks to switch to saved values */ + + +}; + +#define ZONE_ALLOC 128 +#define ZONE_SIZE (MEGABYTES(512)) + +#define MEGABYTE_ALIGNED(vaddr) (!((uint64_t)(vaddr) & MEGABYTE_MASK)) + +#define LKCD_PAGE_HASH_INDEX(paddr) \ + (((paddr) >> lkcd->page_shift) % LKCD_PAGE_HASH) +#define LKCD_PAGES_PER_MEGABYTE() (MEGABYTES(1) / lkcd->page_size) +#define LKCD_PAGE_MEGABYTE(page) ((page) / LKCD_PAGES_PER_MEGABYTE()) +#define LKCD_BENCHMARKS_DONE() (lkcd->benchmarks_done >= lkcd->benchmark_pages) +#define LKCD_VALID_PAGE(flags) ((flags) & LKCD_VALID) + +extern struct lkcd_environment *lkcd; + +#define LKCD_DEBUG(x) (lkcd->debug >= (x)) +#undef BITS +#undef BITS32 +#undef BITS64 +#define BITS() (lkcd->bits) +#define BITS32() (lkcd->bits == 32) +#define BITS64() (lkcd->bits == 64) + +#endif /* LKCD_COMMON */ + +/* + * gdb_interface.c + */ +void gdb_main_loop(int, char **); +void display_gdb_banner(void); +void get_gdb_version(void); +void gdb_session_init(void); +void gdb_interface(struct gnu_request *); +int gdb_pass_through(char *, FILE *, ulong); +int gdb_readmem_callback(ulong, void *, int, int); +int gdb_line_number_callback(ulong, ulong, ulong); +int gdb_print_callback(ulong); +void gdb_error_hook(void); +void restore_gdb_sanity(void); +int is_gdb_command(int, ulong); +char *gdb_command_string(int, char *, int); +void dump_gnu_request(struct gnu_request *, int); +int gdb_CRASHDEBUG(ulong); +void dump_gdb_data(void); +void update_gdb_hooks(void); +void gdb_readnow_warning(void); +int gdb_set_crash_scope(ulong, char *); +extern int *gdb_output_format; +extern unsigned int *gdb_print_max; +extern int *gdb_prettyprint_structs; +extern int *gdb_prettyprint_arrays; +extern int *gdb_repeat_count_threshold; +extern int *gdb_stop_print_at_null; +extern unsigned int *gdb_output_radix; + +/* + * gdb/top.c + */ +extern void execute_command (char *, int); +#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) +extern void (*command_loop_hook)(void); +extern void (*error_hook)(void); +#else +extern void (*deprecated_command_loop_hook)(void); + +/* + * gdb/exceptions.c + */ +extern void (*error_hook)(void); +#endif + +/* + * gdb/symtab.c + */ +extern void gdb_command_funnel(struct gnu_request *); + +/* + * gdb/symfile.c + */ +#if defined(GDB_6_0) || defined(GDB_6_1) +struct objfile; +extern void (*target_new_objfile_hook)(struct objfile *); +#endif + +/* + * gdb/valprint.c + */ +extern unsigned output_radix; +#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) +extern int output_format; +extern int prettyprint_structs; +extern int prettyprint_arrays; +extern int repeat_count_threshold; +extern unsigned int print_max; +extern int stop_print_at_null; +#endif + +#ifdef GDB_7_6 +/* + * gdb/cleanups.c + */ +struct cleanup; +extern struct cleanup *all_cleanups(void); +extern void do_cleanups(struct cleanup *); +#else +/* + * gdb/utils.c + */ +extern void do_cleanups(void *); +#endif + +/* + * gdb/version.c + */ +extern char *version; + +/* + * gdb/disasm.c + */ +#ifdef GDB_5_3 +extern int gdb_disassemble_from_exec; +#endif + +/* + * readline/readline.c + */ +#ifdef GDB_5_3 +extern char *readline(char *); +#else +extern char *readline(const char *); +#endif +extern int rl_editing_mode; + +/* + * readline/history.c + */ +extern int history_offset; + +/* + * external gdb routines + */ +extern int gdb_main_entry(int, char **); +#ifdef GDB_5_3 +extern unsigned long calc_crc32(unsigned long, unsigned char *, size_t); +#else +extern unsigned long gnu_debuglink_crc32 (unsigned long, unsigned char *, size_t); +#endif +extern int have_partial_symbols(void); +extern int have_full_symbols(void); + +#if defined(X86) || defined(X86_64) || defined(IA64) +#define XEN_HYPERVISOR_ARCH +#endif + +#endif /* !GDB_COMMON */ diff --git a/dev.c b/dev.c new file mode 100644 index 00000000..c18f40ec --- /dev/null +++ b/dev.c @@ -0,0 +1,4076 @@ +/* dev.c - core analysis suite + * + * Copyright (C) 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2013 David Anderson + * Copyright (C) 2002-2013 Red Hat, Inc. 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. + */ + +#include "defs.h" + +static void dump_blkdevs(ulong); +static void dump_chrdevs(ulong); +static void dump_blkdevs_v2(ulong); +static void dump_blkdevs_v3(ulong); +static ulong search_cdev_map_probes(char *, int, int, ulong *); +static ulong search_bdev_map_probes(char *, int, int, ulong *); +static void do_pci(void); +static void do_io(void); +static void do_resource_list(ulong, char *, int); + +static const char *pci_strclass (uint, char *); +static const char *pci_strvendor(uint, char *); +static const char *pci_strdev(uint, uint, char *); + +static void diskio_option(void); + +static struct dev_table { + ulong flags; +} dev_table = { 0 }; + +struct dev_table *dt = &dev_table; + +#define DEV_INIT 0x1 +#define DISKIO_INIT 0x2 + +void +dev_init(void) +{ + MEMBER_OFFSET_INIT(pci_dev_global_list, "pci_dev", "global_list"); + MEMBER_OFFSET_INIT(pci_dev_next, "pci_dev", "next"); + MEMBER_OFFSET_INIT(pci_dev_bus, "pci_dev", "bus"); + MEMBER_OFFSET_INIT(pci_dev_devfn, "pci_dev", "devfn"); + MEMBER_OFFSET_INIT(pci_dev_class, "pci_dev", "class"); + MEMBER_OFFSET_INIT(pci_dev_device, "pci_dev", "device"); + MEMBER_OFFSET_INIT(pci_dev_vendor, "pci_dev", "vendor"); + MEMBER_OFFSET_INIT(pci_bus_number, "pci_bus", "number"); + + STRUCT_SIZE_INIT(resource, "resource"); + if ((VALID_STRUCT(resource) && symbol_exists("do_resource_list")) || + (VALID_STRUCT(resource) && + symbol_exists("iomem_resource") && + symbol_exists("ioport_resource"))) { + MEMBER_OFFSET_INIT(resource_name, "resource", "name"); + MEMBER_OFFSET_INIT(resource_start, "resource", "start"); + MEMBER_OFFSET_INIT(resource_end, "resource", "end"); + MEMBER_OFFSET_INIT(resource_sibling, "resource", "sibling"); + MEMBER_OFFSET_INIT(resource_child, "resource", "child"); + } else { + STRUCT_SIZE_INIT(resource_entry_t, "resource_entry_t"); + if (VALID_SIZE(resource_entry_t)) { + MEMBER_OFFSET_INIT(resource_entry_t_from, + "resource_entry_t", "from"); + MEMBER_OFFSET_INIT(resource_entry_t_num, + "resource_entry_t", "num"); + MEMBER_OFFSET_INIT(resource_entry_t_name, + "resource_entry_t", "name"); + MEMBER_OFFSET_INIT(resource_entry_t_next, + "resource_entry_t", "next"); + } + } + + dt->flags |= DEV_INIT; +} + + +/* + * Generic command for character and block device data. + */ +void +cmd_dev(void) +{ + int c; + ulong flags; + + flags = 0; + + while ((c = getopt(argcnt, args, "dpi")) != EOF) { + switch(c) + { + case 'd': + diskio_option(); + return; + + case 'i': + if (machine_type("S390X")) + option_not_supported(c); + do_io(); + return; + + case 'p': + if (machine_type("S390X") || + (THIS_KERNEL_VERSION >= LINUX(2,6,26))) + option_not_supported(c); + do_pci(); + return; + + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + dump_chrdevs(flags); + fprintf(fp, "\n"); + dump_blkdevs(flags); +} + +#define MAX_DEV (255) + +#define MINORBITS 20 +#define MINORMASK ((1U << MINORBITS) - 1) + +#define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS)) +#define MINOR(dev) ((unsigned int) ((dev) & MINORMASK)) + +char *chrdev_hdr = "CHRDEV NAME "; +char *blkdev_hdr = "BLKDEV NAME "; + +/* + * Dump the character device data. + */ +static void +dump_chrdevs(ulong flags) +{ + int i; + ulong addr, size; + char buf[BUFSIZE]; + char buf2[BUFSIZE]; + struct chrdevs { + ulong name; + ulong ops; + } chrdevs[MAX_DEV], *cp; + ulong *cdp; + char *char_device_struct_buf; + ulong next, savenext, name, fops, cdev; + int major, minor; + int name_typecode; + size_t name_size; + + if (!symbol_exists("chrdevs")) + error(FATAL, "chrdevs: symbol does not exist\n"); + + addr = symbol_value("chrdevs"); + size = VALID_STRUCT(char_device_struct) ? + sizeof(void *) : sizeof(struct chrdevs); + + readmem(addr, KVADDR, &chrdevs[0], size * MAX_DEV, + "chrdevs array", FAULT_ON_ERROR); + + fprintf(fp, "%s %s", chrdev_hdr, VADDR_PRLEN == 8 ? " " : ""); + fprintf(fp, "%s ", mkstring(buf, VADDR_PRLEN, CENTER, "CDEV")); + fprintf(fp, "%s\n", mkstring(buf, VADDR_PRLEN, LJUST, "OPERATIONS")); + + if (VALID_STRUCT(char_device_struct)) + goto char_device_struct; + + for (i = 0, cp = &chrdevs[0]; i < MAX_DEV; i++, cp++) { + if (!cp->ops) + continue; + + fprintf(fp, " %3d ", i); + if (cp->name) { + if (read_string(cp->name, buf, BUFSIZE-1)) + fprintf(fp, "%-11s ", buf); + else + fprintf(fp, "%-11s ", "(unknown)"); + + } else + fprintf(fp, "%-11s ", "(unknown)"); + + sprintf(buf, "%s%%%dlx ", + strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", + VADDR_PRLEN); + fprintf(fp, buf, cp->ops); + value_to_symstr(cp->ops, buf, 0); + if (strlen(buf)) + fprintf(fp, "<%s>", buf); + + fprintf(fp, "\n"); + } + return; + +char_device_struct: + + char_device_struct_buf = GETBUF(SIZE(char_device_struct)); + cdp = (ulong *)&chrdevs[0]; + name_typecode = MEMBER_TYPE("char_device_struct", "name"); + name_size = (size_t)MEMBER_SIZE("char_device_struct", "name"); + + for (i = 0; i < MAX_DEV; i++, cdp++) { + if (!(*cdp)) + continue; + + readmem(*cdp, KVADDR, char_device_struct_buf, + SIZE(char_device_struct), + "char_device_struct", FAULT_ON_ERROR); + + next = ULONG(char_device_struct_buf + + OFFSET(char_device_struct_next)); + name = ULONG(char_device_struct_buf + + OFFSET(char_device_struct_name)); + switch (name_typecode) + { + case TYPE_CODE_ARRAY: + snprintf(buf, name_size, "%s", + char_device_struct_buf + + OFFSET(char_device_struct_name)); + break; + case TYPE_CODE_PTR: + default: + if (!name || !read_string(name, buf, BUFSIZE-1)) + break; + } + + major = INT(char_device_struct_buf + + OFFSET(char_device_struct_major)); + minor = INT(char_device_struct_buf + + OFFSET(char_device_struct_baseminor)); + + cdev = fops = 0; + if (VALID_MEMBER(char_device_struct_cdev) && + VALID_STRUCT(cdev)) { + cdev = ULONG(char_device_struct_buf + + OFFSET(char_device_struct_cdev)); + if (cdev) { + addr = cdev + OFFSET(cdev_ops); + readmem(addr, KVADDR, &fops, + sizeof(void *), + "cdev ops", FAULT_ON_ERROR); + } + } else { + fops = ULONG(char_device_struct_buf + + OFFSET(char_device_struct_fops)); + } + + if (!fops) + fops = search_cdev_map_probes(buf, major, minor, &cdev); + + if (!fops) { + fprintf(fp, " %3d ", major); + fprintf(fp, "%-13s ", buf); + fprintf(fp, "%s%s\n", VADDR_PRLEN == 8 ? " " : " ", + mkstring(buf, VADDR_PRLEN, CENTER, "(none)")); + } else { + fprintf(fp, " %3d ", major); + fprintf(fp, "%-13s ", buf); + sprintf(buf2, "%s%%%dlx ", + strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", + VADDR_PRLEN); + fprintf(fp, buf2, cdev); + value_to_symstr(fops, buf2, 0); + if (strlen(buf2)) + fprintf(fp, "%s", buf2); + else + fprintf(fp, "%lx", fops); + fprintf(fp, "\n"); + } + + if (CRASHDEBUG(1)) + fprintf(fp, + "%lx: major: %d minor: %d name: %s next: %lx cdev: %lx fops: %lx\n", + *cdp, major, minor, buf, next, cdev, fops); + + while (next) { + readmem(savenext = next, KVADDR, char_device_struct_buf, + SIZE(char_device_struct), + "char_device_struct", FAULT_ON_ERROR); + + next = ULONG(char_device_struct_buf + + OFFSET(char_device_struct_next)); + name = ULONG(char_device_struct_buf + + OFFSET(char_device_struct_name)); + switch (name_typecode) + { + case TYPE_CODE_ARRAY: + snprintf(buf, name_size, "%s", + char_device_struct_buf + + OFFSET(char_device_struct_name)); + break; + case TYPE_CODE_PTR: + default: + if (!name || !read_string(name, buf, BUFSIZE-1)) + sprintf(buf, "(unknown)"); + break; + } + + major = INT(char_device_struct_buf + + OFFSET(char_device_struct_major)); + minor = INT(char_device_struct_buf + + OFFSET(char_device_struct_baseminor)); + + fops = cdev = 0; + if (VALID_MEMBER(char_device_struct_cdev) && + VALID_STRUCT(cdev)) { + cdev = ULONG(char_device_struct_buf + + OFFSET(char_device_struct_cdev)); + if (cdev) { + addr = cdev + OFFSET(cdev_ops); + readmem(addr, KVADDR, &fops, + sizeof(void *), + "cdev ops", FAULT_ON_ERROR); + } + } else { + fops = ULONG(char_device_struct_buf + + OFFSET(char_device_struct_fops)); + } + + if (!fops) + fops = search_cdev_map_probes(buf, major, minor, &cdev); + + if (!fops) { + fprintf(fp, " %3d ", major); + fprintf(fp, "%-13s ", buf); + fprintf(fp, "%s%s\n", VADDR_PRLEN == 8 ? " " : " ", + mkstring(buf, VADDR_PRLEN, CENTER, "(none)")); + } else { + fprintf(fp, " %3d ", major); + fprintf(fp, "%-13s ", buf); + sprintf(buf2, "%s%%%dlx ", + strlen("OPERATIONS") < VADDR_PRLEN ? + " " : " ", VADDR_PRLEN); + fprintf(fp, buf2, cdev); + value_to_symstr(fops, buf2, 0); + if (strlen(buf2)) + fprintf(fp, "%s", buf2); + else + fprintf(fp, "%lx", fops); + fprintf(fp, "\n"); + } + + if (CRASHDEBUG(1)) + fprintf(fp, + "%lx: major: %d minor: %d name: %s next: %lx cdev: %lx fops: %lx\n", + savenext, major, minor, buf, next, cdev, fops); + } + } + + FREEBUF(char_device_struct_buf); +} + +/* + * Search for a major/minor match by following the list headed + * by the kobj_map.probes[major] array entry. The "data" member + * points to a cdev structure containing the file_operations + * pointer. + */ +static ulong +search_cdev_map_probes(char *name, int major, int minor, ulong *cdev) +{ + char *probe_buf; + ulong probes[MAX_DEV]; + ulong cdev_map, addr, next, ops, probe_data; + uint probe_dev; + + if (kernel_symbol_exists("cdev_map")) + get_symbol_data("cdev_map", sizeof(ulong), &cdev_map); + else + return 0; + + addr = cdev_map + OFFSET(kobj_map_probes); + if (!readmem(addr, KVADDR, &probes[0], sizeof(void *) * MAX_DEV, + "cdev_map.probes[]", QUIET|RETURN_ON_ERROR)) + return 0; + + ops = 0; + probe_buf = GETBUF(SIZE(probe)); + next = probes[major]; + + while (next) { + if (!readmem(next, KVADDR, probe_buf, SIZE(probe), + "struct probe", QUIET|RETURN_ON_ERROR)) + break; + + probe_dev = UINT(probe_buf + OFFSET(probe_dev)); + + if ((MAJOR(probe_dev) == major) && + (MINOR(probe_dev) == minor)) { + probe_data = ULONG(probe_buf + OFFSET(probe_data)); + addr = probe_data + OFFSET(cdev_ops); + if (!readmem(addr, KVADDR, &ops, sizeof(void *), + "cdev ops", QUIET|RETURN_ON_ERROR)) + ops = 0; + else + *cdev = probe_data; + break; + } + + next = ULONG(probe_buf + OFFSET(probe_next)); + } + + FREEBUF(probe_buf); + return ops; +} + +/* + * Dump the block device data. + */ +static void +dump_blkdevs(ulong flags) +{ + int i; + ulong addr; + char buf[BUFSIZE]; + struct blkdevs { + ulong name; + ulong ops; + } blkdevs[MAX_DEV], *bp; + + if (kernel_symbol_exists("major_names") && + kernel_symbol_exists("bdev_map")) { + dump_blkdevs_v3(flags); + return; + } + + if (symbol_exists("all_bdevs")) { + dump_blkdevs_v2(flags); + return; + } + + if (!symbol_exists("blkdevs")) + error(FATAL, "blkdevs or all_bdevs: symbols do not exist\n"); + + addr = symbol_value("blkdevs"); + readmem(addr, KVADDR, &blkdevs[0], sizeof(struct blkdevs) * MAX_DEV, + "blkdevs array", FAULT_ON_ERROR); + + fprintf(fp, "%s%s\n", blkdev_hdr, + mkstring(buf, VADDR_PRLEN, CENTER, "OPERATIONS")); + + for (i = 0, bp = &blkdevs[0]; i < MAX_DEV; i++, bp++) { + if (!bp->ops) + continue; + + fprintf(fp, " %3d ", i); + if (bp->name) { + if (read_string(bp->name, buf, BUFSIZE-1)) + fprintf(fp, "%-11s ", buf); + else + fprintf(fp, "%-11s ", "(unknown)"); + + } else + fprintf(fp, "%-11s ", "(unknown)"); + + sprintf(buf, "%s%%%dlx ", + strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", + VADDR_PRLEN); + fprintf(fp, buf, bp->ops); + + value_to_symstr(bp->ops, buf, 0); + if (strlen(buf)) + fprintf(fp, "<%s>", buf); + + fprintf(fp, "\n"); + } +} + +/* + * block device dump for 2.6 + */ +static void +dump_blkdevs_v2(ulong flags) +{ + struct list_data list_data, *ld; + ulong *major_fops, *bdevlist, *gendisklist, *majorlist; + int i, j, bdevcnt, len; + char *block_device_buf, *gendisk_buf, *blk_major_name_buf; + ulong next, savenext, fops; + int major, total; + char buf[BUFSIZE]; + + if (!symbol_exists("major_names")) + error(FATAL, + "major_names[] array doesn't exist in this kernel\n"); + + len = get_array_length("major_names", NULL, 0); + + block_device_buf = GETBUF(SIZE(block_device)); + gendisk_buf = GETBUF(SIZE(gendisk)); + + ld = &list_data; + BZERO(ld, sizeof(struct list_data)); + + get_symbol_data("all_bdevs", sizeof(void *), &ld->start); + ld->end = symbol_value("all_bdevs"); + ld->list_head_offset = OFFSET(block_device_bd_list); + + hq_open(); + bdevcnt = do_list(ld); + bdevlist = (ulong *)GETBUF(bdevcnt * sizeof(ulong)); + gendisklist = (ulong *)GETBUF(bdevcnt * sizeof(ulong)); + bdevcnt = retrieve_list(bdevlist, bdevcnt); + hq_close(); + + total = MAX(len, bdevcnt); + major_fops = (ulong *)GETBUF(sizeof(void *) * total); + + /* + * go through the block_device list, emulating: + * + * ret += bdev->bd_inode->i_mapping->nrpages; + */ + for (i = 0; i < bdevcnt; i++) { + readmem(bdevlist[i], KVADDR, block_device_buf, + SIZE(block_device), "block_device buffer", + FAULT_ON_ERROR); + gendisklist[i] = ULONG(block_device_buf + + OFFSET(block_device_bd_disk)); + if (CRASHDEBUG(1)) + fprintf(fp, "[%d] %lx -> %lx\n", + i, bdevlist[i], gendisklist[i]); + } + + for (i = 1; i < bdevcnt; i++) { + for (j = 0; j < i; j++) { + if (gendisklist[i] == gendisklist[j]) + gendisklist[i] = 0; + } + } + + for (i = 0; i < bdevcnt; i++) { + if (!gendisklist[i]) + continue; + readmem(gendisklist[i], KVADDR, gendisk_buf, + SIZE(gendisk), "gendisk buffer", + FAULT_ON_ERROR); + fops = ULONG(gendisk_buf + OFFSET(gendisk_fops)); + major = UINT(gendisk_buf + OFFSET(gendisk_major)); + strncpy(buf, gendisk_buf + OFFSET(gendisk_disk_name), 32); + if (CRASHDEBUG(1)) + fprintf(fp, "%lx: name: [%s] major: %d fops: %lx\n", + gendisklist[i], buf, major, fops); + + if (fops && (major < total)) + major_fops[major] = fops; + } + + FREEBUF(bdevlist); + FREEBUF(gendisklist); + FREEBUF(block_device_buf); + FREEBUF(gendisk_buf); + + if (CRASHDEBUG(1)) + fprintf(fp, "major_names[%d]\n", len); + majorlist = (ulong *)GETBUF(len * sizeof(void *)); + blk_major_name_buf = GETBUF(SIZE(blk_major_name)); + readmem(symbol_value("major_names"), KVADDR, &majorlist[0], + sizeof(void *) * len, "major_names array", FAULT_ON_ERROR); + + fprintf(fp, "%s%s\n", blkdev_hdr, + mkstring(buf, VADDR_PRLEN, CENTER, "OPERATIONS")); + + for (i = 0; i < len; i++) { + if (!majorlist[i]) + continue; + + readmem(majorlist[i], KVADDR, blk_major_name_buf, + SIZE(blk_major_name), "blk_major_name buffer", + FAULT_ON_ERROR); + + major = UINT(blk_major_name_buf + + OFFSET(blk_major_name_major)); + buf[0] = NULLCHAR; + strncpy(buf, blk_major_name_buf + + OFFSET(blk_major_name_name), 16); + next = ULONG(blk_major_name_buf + + OFFSET(blk_major_name_next)); + if (CRASHDEBUG(1)) + fprintf(fp, + "[%d] %lx major: %d name: %s next: %lx fops: %lx\n", + i, majorlist[i], major, buf, next, + major_fops[major]); + + fprintf(fp, " %3d ", major); + fprintf(fp, "%-12s ", strlen(buf) ? buf : "(unknown)"); + if (major_fops[major]) { + sprintf(buf, "%s%%%dlx ", + strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", + VADDR_PRLEN); + fprintf(fp, buf, major_fops[major]); + value_to_symstr(major_fops[major], buf, 0); + if (strlen(buf)) + fprintf(fp, "<%s>", buf); + } else + fprintf(fp, " (unknown)"); + fprintf(fp, "\n"); + + while (next) { + readmem(savenext = next, KVADDR, blk_major_name_buf, + SIZE(blk_major_name), "blk_major_name buffer", + FAULT_ON_ERROR); + major = UINT(blk_major_name_buf + + OFFSET(blk_major_name_major)); + strncpy(buf, blk_major_name_buf + + OFFSET(blk_major_name_name), 16); + next = ULONG(blk_major_name_buf + + OFFSET(blk_major_name_next)); + if (CRASHDEBUG(1)) + fprintf(fp, + "[%d] %lx major: %d name: %s next: %lx fops: %lx\n", + i, savenext, major, buf, next, + major_fops[major]); + + fprintf(fp, " %3d ", major); + fprintf(fp, "%-12s ", strlen(buf) ? buf : "(unknown)"); + if (major_fops[major]) { + sprintf(buf, "%s%%%dlx ", + strlen("OPERATIONS") < VADDR_PRLEN ? + " " : " ", VADDR_PRLEN); + fprintf(fp, buf, major_fops[major]); + value_to_symstr(major_fops[major], buf, 0); + if (strlen(buf)) + fprintf(fp, "<%s>", buf); + } else + fprintf(fp, " (unknown)"); + fprintf(fp, "\n"); + } + } + + FREEBUF(majorlist); + FREEBUF(major_fops); + FREEBUF(blk_major_name_buf); +} + +static void +dump_blkdevs_v3(ulong flags) +{ + int i, len; + ulong blk_major_name; + char *blk_major_name_buf; + char buf[BUFSIZE]; + uint major; + ulong gendisk, addr, fops; + + if (!(len = get_array_length("major_names", NULL, 0))) + len = MAX_DEV; + + fprintf(fp, "%s %s", blkdev_hdr, VADDR_PRLEN == 8 ? " " : ""); + fprintf(fp, "%s ", mkstring(buf, VADDR_PRLEN, CENTER|RJUST, "GENDISK")); + fprintf(fp, "%s\n", mkstring(buf, VADDR_PRLEN, LJUST, "OPERATIONS")); + + blk_major_name_buf = GETBUF(SIZE(blk_major_name)); + gendisk = 0; + + for (i = 0; i < len; i++) { + addr = symbol_value("major_names") + (i * sizeof(void *)); + readmem(addr, KVADDR, &blk_major_name, sizeof(void *), + "major_names[] entry", FAULT_ON_ERROR); + + if (!blk_major_name) + continue; + + readmem(blk_major_name, KVADDR, blk_major_name_buf, + SIZE(blk_major_name), "blk_major_name", FAULT_ON_ERROR); + + major = UINT(blk_major_name_buf + + OFFSET(blk_major_name_major)); + buf[0] = NULLCHAR; + strncpy(buf, blk_major_name_buf + + OFFSET(blk_major_name_name), 16); + + fops = search_bdev_map_probes(buf, major == i ? major : i, + UNUSED, &gendisk); + + if (CRASHDEBUG(1)) + fprintf(fp, "blk_major_name: %lx block major: %d name: %s gendisk: %lx fops: %lx\n", + blk_major_name, major, buf, gendisk, fops); + + if (!fops) { + fprintf(fp, " %3d ", major); + fprintf(fp, "%-13s ", + strlen(buf) ? buf : "(unknown)"); + fprintf(fp, "%s%s\n", VADDR_PRLEN == 8 ? " " : " ", + mkstring(buf, VADDR_PRLEN, CENTER, "(none)")); + continue; + } + + fprintf(fp, " %3d ", major); + fprintf(fp, "%-13s ", strlen(buf) ? buf : "(unknown)"); + sprintf(buf, "%s%%%dlx ", + strlen("OPERATIONS") < VADDR_PRLEN ? " " : " ", + VADDR_PRLEN); + fprintf(fp, buf, gendisk); + value_to_symstr(fops, buf, 0); + if (strlen(buf)) + fprintf(fp, "%s", buf); + else + fprintf(fp, "%lx", fops); + fprintf(fp, "\n"); + } +} + +static ulong +search_bdev_map_probes(char *name, int major, int minor, ulong *gendisk) +{ + char *probe_buf, *gendisk_buf; + ulong probes[MAX_DEV]; + ulong bdev_map, addr, next, probe_data, fops; + uint probe_dev; + + get_symbol_data("bdev_map", sizeof(ulong), &bdev_map); + + addr = bdev_map + OFFSET(kobj_map_probes); + if (!readmem(addr, KVADDR, &probes[0], sizeof(void *) * MAX_DEV, + "bdev_map.probes[]", QUIET|RETURN_ON_ERROR)) + return 0; + + probe_buf = GETBUF(SIZE(probe)); + gendisk_buf = GETBUF(SIZE(gendisk)); + + fops = 0; + + for (next = probes[major]; next; + next = ULONG(probe_buf + OFFSET(probe_next))) { + + if (!readmem(next, KVADDR, probe_buf, SIZE(probe), + "struct probe", QUIET|RETURN_ON_ERROR)) + break; + + probe_data = ULONG(probe_buf + OFFSET(probe_data)); + if (!probe_data) + continue; + + probe_dev = UINT(probe_buf + OFFSET(probe_dev)); + if (MAJOR(probe_dev) != major) + continue; + + if (!readmem(probe_data, KVADDR, gendisk_buf, + SIZE(gendisk), "gendisk buffer", + QUIET|RETURN_ON_ERROR)) + break; + + fops = ULONG(gendisk_buf + OFFSET(gendisk_fops)); + + if (fops) { + *gendisk = probe_data; + break; + } + } + + FREEBUF(probe_buf); + FREEBUF(gendisk_buf); + return fops; +} + +void +dump_dev_table(void) +{ + struct dev_table *dt; + int others; + + dt = &dev_table; + others = 0; + + fprintf(fp, " flags: %lx (", dt->flags); + if (dt->flags & DEV_INIT) + fprintf(fp, "%sDEV_INIT", others++ ? "|" : ""); + if (dt->flags & DISKIO_INIT) + fprintf(fp, "%sDISKIO_INIT", others++ ? "|" : ""); + fprintf(fp, ")\n"); +} + +/* + * Dump the I/O ports. + */ + +static void +do_io(void) +{ + int i, c, len, wrap, cnt, size; + ulong *resource_list, name, start, end; + char *resource_buf, *p1; + struct list_data list_data, *ld; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + + if (symbol_exists("get_ioport_list")) /* linux 2.2 */ + goto ioport_list; + if (symbol_exists("do_resource_list")) /* linux 2.4 */ + goto resource_list; + if (symbol_exists("iomem_resource") && symbol_exists("ioport_resource")) + goto resource_list; + return; + +ioport_list: + /* + * ioport + */ + fprintf(fp, "%s %s NAME\n", + mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "RESOURCE"), + mkstring(buf2, 9, CENTER|LJUST, "RANGE")); + + wrap = VADDR_PRLEN + 2 + 9 + 2; + + resource_buf = GETBUF(SIZE(resource_entry_t)); + ld = &list_data; + BZERO(ld, sizeof(struct list_data)); + ld->start = 0xc026cf20; + readmem(symbol_value("iolist") + OFFSET(resource_entry_t_next), + KVADDR, &ld->start, sizeof(void *), "iolist.next", + FAULT_ON_ERROR); + ld->member_offset = OFFSET(resource_entry_t_next); + + hq_open(); + cnt = do_list(ld); + if (!cnt) + return; + resource_list = (ulong *)GETBUF(cnt * sizeof(ulong)); + cnt = retrieve_list(resource_list, cnt); + hq_close(); + + for (i = 0; i < cnt; i++) { + fprintf(fp, "%lx ", resource_list[i]); + readmem(resource_list[i], KVADDR, resource_buf, + SIZE(resource_entry_t), "resource_entry_t", + FAULT_ON_ERROR); + start = ULONG(resource_buf + OFFSET(resource_entry_t_from)); + end = ULONG(resource_buf + OFFSET(resource_entry_t_num)); + end += start; + fprintf(fp, "%04lx-%04lx ", start, end); + name = ULONG(resource_buf + OFFSET(resource_entry_t_name)); + if (!read_string(name, buf1, BUFSIZE-1)) + sprintf(buf1, "(unknown)"); + + if (wrap + strlen(buf1) <= 80) + fprintf(fp, "%s\n", buf1); + else { + len = wrap + strlen(buf1) - 80; + for (c = 0, p1 = &buf1[strlen(buf1)-1]; + p1 > buf1; p1--, c++) { + if (*p1 != ' ') + continue; + if (c >= len) { + *p1 = NULLCHAR; + break; + } + } + fprintf(fp, "%s\n", buf1); + if (*p1 == NULLCHAR) { + pad_line(fp, wrap, ' '); + fprintf(fp, "%s\n", p1+1); + } + } + } + + return; + +resource_list: + resource_buf = GETBUF(SIZE(resource)); + /* + * ioport + */ + readmem(symbol_value("ioport_resource") + OFFSET(resource_end), + KVADDR, &end, sizeof(long), "ioport_resource.end", + FAULT_ON_ERROR); + + size = (end > 0xffff) ? 8 : 4; + + fprintf(fp, "%s %s NAME\n", + mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "RESOURCE"), + mkstring(buf2, (size*2) + 1, + CENTER|LJUST, "RANGE")); + do_resource_list(symbol_value("ioport_resource"), resource_buf, size); + + /* + * iomem + */ + readmem(symbol_value("iomem_resource") + OFFSET(resource_end), + KVADDR, &end, sizeof(long), "iomem_resource.end", + FAULT_ON_ERROR); + size = (end > 0xffff) ? 8 : 4; + fprintf(fp, "\n%s %s NAME\n", + mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "RESOURCE"), + mkstring(buf2, (size*2) + 1, + CENTER|LJUST, "RANGE")); + do_resource_list(symbol_value("iomem_resource"), resource_buf, size); + + return; +} + +static void +do_resource_list(ulong first_entry, char *resource_buf, int size) +{ + ulong entry, name, start, end, child, sibling; + int c, wrap, len; + char buf1[BUFSIZE]; + char *fmt, *p1; + + fmt = NULL; + + switch (size) + { + case 4: + fmt = "%8lx %04lx-%04lx"; + break; + case 8: + fmt = "%8lx %08lx-%08lx"; + break; + } + wrap = VADDR_PRLEN + 2 + ((size*2)+1) + 2; + + entry = first_entry; + + while (entry) { + readmem(entry, KVADDR, resource_buf, + SIZE(resource), "resource", FAULT_ON_ERROR); + + start = ULONG(resource_buf + OFFSET(resource_start)); + end = ULONG(resource_buf + OFFSET(resource_end)); + name = ULONG(resource_buf + OFFSET(resource_name)); + child = ULONG(resource_buf + OFFSET(resource_child)); + sibling = ULONG(resource_buf + OFFSET(resource_sibling)); + + if (!read_string(name, buf1, BUFSIZE-1)) + sprintf(buf1, "(unknown)"); + + fprintf(fp, fmt, entry, start, end); + if (wrap + strlen(buf1) <= 80) + fprintf(fp, " %s\n", buf1); + else { + len = wrap + strlen(buf1) - 80; + for (c = 0, p1 = &buf1[strlen(buf1)-1]; + p1 > buf1; p1--, c++) { + if (*p1 != ' ') + continue; + if (c >= len) { + *p1 = NULLCHAR; + break; + } + } + fprintf(fp, " %s\n", buf1); + if (*p1 == NULLCHAR) { + pad_line(fp, wrap, ' '); + fprintf(fp, "%s\n", p1+1); + } + } + + if (child && (child != entry)) + do_resource_list(child, resource_buf, size); + + entry = sibling; + } +} + + +/* + * PCI defines taken from 2.2.17 version of pci.h + */ + +#define USE_2_2_17_PCI_H + +#ifdef USE_2_2_17_PCI_H +/* + * PCI defines and function prototypes + * Copyright 1994, Drew Eckhardt + * Copyright 1997--1999 Martin Mares + * + * For more information, please consult the following manuals (look at + * http://www.pcisig.com/ for how to get them): + * + * PCI BIOS Specification + * PCI Local Bus Specification + * PCI to PCI Bridge Specification + * PCI System Design Guide + */ + +/* + * Under PCI, each device has 256 bytes of configuration address space, + * of which the first 64 bytes are standardized as follows: + */ +#define PCI_VENDOR_ID 0x00 /* 16 bits */ +#define PCI_DEVICE_ID 0x02 /* 16 bits */ +#define PCI_COMMAND 0x04 /* 16 bits */ +#define PCI_COMMAND_IO 0x1 /* Enable response in I/O space */ +#define PCI_COMMAND_MEMORY 0x2 /* Enable response in Memory space */ +#define PCI_COMMAND_MASTER 0x4 /* Enable bus mastering */ +#define PCI_COMMAND_SPECIAL 0x8 /* Enable response to special cycles */ +#define PCI_COMMAND_INVALIDATE 0x10 /* Use memory write and invalidate */ +#define PCI_COMMAND_VGA_PALETTE 0x20 /* Enable palette snooping */ +#define PCI_COMMAND_PARITY 0x40 /* Enable parity checking */ +#define PCI_COMMAND_WAIT 0x80 /* Enable address/data stepping */ +#define PCI_COMMAND_SERR 0x100 /* Enable SERR */ +#define PCI_COMMAND_FAST_BACK 0x200 /* Enable back-to-back writes */ + +#define PCI_STATUS 0x06 /* 16 bits */ +#define PCI_STATUS_CAP_LIST 0x10 /* Support Capability List */ +#define PCI_STATUS_66MHZ 0x20 /* Support 66 Mhz PCI 2.1 bus */ +#define PCI_STATUS_UDF 0x40 /* Support User Definable Features */ +#define PCI_STATUS_FAST_BACK 0x80 /* Accept fast-back to back */ +#define PCI_STATUS_PARITY 0x100 /* Detected parity error */ +#define PCI_STATUS_DEVSEL_MASK 0x600 /* DEVSEL timing */ +#define PCI_STATUS_DEVSEL_FAST 0x000 +#define PCI_STATUS_DEVSEL_MEDIUM 0x200 +#define PCI_STATUS_DEVSEL_SLOW 0x400 +#define PCI_STATUS_SIG_TARGET_ABORT 0x800 /* Set on target abort */ +#define PCI_STATUS_REC_TARGET_ABORT 0x1000 /* Master ack of " */ +#define PCI_STATUS_REC_MASTER_ABORT 0x2000 /* Set on master abort */ +#define PCI_STATUS_SIG_SYSTEM_ERROR 0x4000 /* Set when we drive SERR */ +#define PCI_STATUS_DETECTED_PARITY 0x8000 /* Set on parity error */ + +#define PCI_CLASS_REVISION 0x08 /* High 24 bits are class, low 8 + revision */ +#define PCI_REVISION_ID 0x08 /* Revision ID */ +#define PCI_CLASS_PROG 0x09 /* Reg. Level Programming Interface */ +#define PCI_CLASS_DEVICE 0x0a /* Device class */ + +#define PCI_CACHE_LINE_SIZE 0x0c /* 8 bits */ +#define PCI_LATENCY_TIMER 0x0d /* 8 bits */ +#define PCI_HEADER_TYPE 0x0e /* 8 bits */ +#define PCI_HEADER_TYPE_NORMAL 0 +#define PCI_HEADER_TYPE_BRIDGE 1 +#define PCI_HEADER_TYPE_CARDBUS 2 + +#define PCI_BIST 0x0f /* 8 bits */ +#define PCI_BIST_CODE_MASK 0x0f /* Return result */ +#define PCI_BIST_START 0x40 /* 1 to start BIST, 2 secs or less */ +#define PCI_BIST_CAPABLE 0x80 /* 1 if BIST capable */ + +/* + * Base addresses specify locations in memory or I/O space. + * Decoded size can be determined by writing a value of + * 0xffffffff to the register, and reading it back. Only + * 1 bits are decoded. + */ +#define PCI_BASE_ADDRESS_0 0x10 /* 32 bits */ +#define PCI_BASE_ADDRESS_1 0x14 /* 32 bits [htype 0,1 only] */ +#define PCI_BASE_ADDRESS_2 0x18 /* 32 bits [htype 0 only] */ +#define PCI_BASE_ADDRESS_3 0x1c /* 32 bits */ +#define PCI_BASE_ADDRESS_4 0x20 /* 32 bits */ +#define PCI_BASE_ADDRESS_5 0x24 /* 32 bits */ +#define PCI_BASE_ADDRESS_SPACE 0x01 /* 0 = memory, 1 = I/O */ +#define PCI_BASE_ADDRESS_SPACE_IO 0x01 +#define PCI_BASE_ADDRESS_SPACE_MEMORY 0x00 +#define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06 +#define PCI_BASE_ADDRESS_MEM_TYPE_32 0x00 /* 32 bit address */ +#define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02 /* Below 1M */ +#define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04 /* 64 bit address */ +#define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08 /* prefetchable? */ +#define PCI_BASE_ADDRESS_MEM_MASK (~0x0fUL) +#define PCI_BASE_ADDRESS_IO_MASK (~0x03UL) +/* bit 1 is reserved if address_space = 1 */ + +/* Header type 0 (normal devices) */ +#define PCI_CARDBUS_CIS 0x28 +#define PCI_SUBSYSTEM_VENDOR_ID 0x2c +#define PCI_SUBSYSTEM_ID 0x2e +#define PCI_ROM_ADDRESS 0x30 /* Bits 31..11 are address, 10..1 reserved */ +#define PCI_ROM_ADDRESS_ENABLE 0x01 +#define PCI_ROM_ADDRESS_MASK (~0x7ffUL) + +#define PCI_CAPABILITY_LIST 0x34 /* Offset of first capability list entry */ + +/* 0x35-0x3b are reserved */ +#define PCI_INTERRUPT_LINE 0x3c /* 8 bits */ +#define PCI_INTERRUPT_PIN 0x3d /* 8 bits */ +#define PCI_MIN_GNT 0x3e /* 8 bits */ +#define PCI_MAX_LAT 0x3f /* 8 bits */ + +/* Header type 1 (PCI-to-PCI bridges) */ +#define PCI_PRIMARY_BUS 0x18 /* Primary bus number */ +#define PCI_SECONDARY_BUS 0x19 /* Secondary bus number */ +#define PCI_SUBORDINATE_BUS 0x1a /* Highest bus number behind the bridge */ +#define PCI_SEC_LATENCY_TIMER 0x1b /* Latency timer for secondary interface */ +#define PCI_IO_BASE 0x1c /* I/O range behind the bridge */ +#define PCI_IO_LIMIT 0x1d +#define PCI_IO_RANGE_TYPE_MASK 0x0f /* I/O bridging type */ +#define PCI_IO_RANGE_TYPE_16 0x00 +#define PCI_IO_RANGE_TYPE_32 0x01 +#define PCI_IO_RANGE_MASK ~0x0f +#define PCI_SEC_STATUS 0x1e /* Secondary status register, only bit 14 used */ +#define PCI_MEMORY_BASE 0x20 /* Memory range behind */ +#define PCI_MEMORY_LIMIT 0x22 +#define PCI_MEMORY_RANGE_TYPE_MASK 0x0f +#define PCI_MEMORY_RANGE_MASK ~0x0f +#define PCI_PREF_MEMORY_BASE 0x24 /* Prefetchable memory range behind */ +#define PCI_PREF_MEMORY_LIMIT 0x26 +#define PCI_PREF_RANGE_TYPE_MASK 0x0f +#define PCI_PREF_RANGE_TYPE_32 0x00 +#define PCI_PREF_RANGE_TYPE_64 0x01 +#define PCI_PREF_RANGE_MASK ~0x0f +#define PCI_PREF_BASE_UPPER32 0x28 /* Upper half of prefetchable memory range */ +#define PCI_PREF_LIMIT_UPPER32 0x2c +#define PCI_IO_BASE_UPPER16 0x30 /* Upper half of I/O addresses */ +#define PCI_IO_LIMIT_UPPER16 0x32 +/* 0x34-0x3b is reserved */ +#define PCI_ROM_ADDRESS1 0x38 /* Same as PCI_ROM_ADDRESS, but for htype 1 */ +/* 0x3c-0x3d are same as for htype 0 */ +#define PCI_BRIDGE_CONTROL 0x3e +#define PCI_BRIDGE_CTL_PARITY 0x01 /* Enable parity detection on secondary interface */ +#define PCI_BRIDGE_CTL_SERR 0x02 /* The same for SERR forwarding */ +#define PCI_BRIDGE_CTL_NO_ISA 0x04 /* Disable bridging of ISA ports */ +#define PCI_BRIDGE_CTL_VGA 0x08 /* Forward VGA addresses */ +#define PCI_BRIDGE_CTL_MASTER_ABORT 0x20 /* Report master aborts */ +#define PCI_BRIDGE_CTL_BUS_RESET 0x40 /* Secondary bus reset */ +#define PCI_BRIDGE_CTL_FAST_BACK 0x80 /* Fast Back2Back enabled on secondary interface */ + +/* Header type 2 (CardBus bridges) */ +/* 0x14-0x15 reserved */ +#define PCI_CB_SEC_STATUS 0x16 /* Secondary status */ +#define PCI_CB_PRIMARY_BUS 0x18 /* PCI bus number */ +#define PCI_CB_CARD_BUS 0x19 /* CardBus bus number */ +#define PCI_CB_SUBORDINATE_BUS 0x1a /* Subordinate bus number */ +#define PCI_CB_LATENCY_TIMER 0x1b /* CardBus latency timer */ +#define PCI_CB_MEMORY_BASE_0 0x1c +#define PCI_CB_MEMORY_LIMIT_0 0x20 +#define PCI_CB_MEMORY_BASE_1 0x24 +#define PCI_CB_MEMORY_LIMIT_1 0x28 +#define PCI_CB_IO_BASE_0 0x2c +#define PCI_CB_IO_BASE_0_HI 0x2e +#define PCI_CB_IO_LIMIT_0 0x30 +#define PCI_CB_IO_LIMIT_0_HI 0x32 +#define PCI_CB_IO_BASE_1 0x34 +#define PCI_CB_IO_BASE_1_HI 0x36 +#define PCI_CB_IO_LIMIT_1 0x38 +#define PCI_CB_IO_LIMIT_1_HI 0x3a +#define PCI_CB_IO_RANGE_MASK ~0x03 +/* 0x3c-0x3d are same as for htype 0 */ +#define PCI_CB_BRIDGE_CONTROL 0x3e +#define PCI_CB_BRIDGE_CTL_PARITY 0x01 /* Similar to standard bridge control register */ +#define PCI_CB_BRIDGE_CTL_SERR 0x02 +#define PCI_CB_BRIDGE_CTL_ISA 0x04 +#define PCI_CB_BRIDGE_CTL_VGA 0x08 +#define PCI_CB_BRIDGE_CTL_MASTER_ABORT 0x20 +#define PCI_CB_BRIDGE_CTL_CB_RESET 0x40 /* CardBus reset */ +#define PCI_CB_BRIDGE_CTL_16BIT_INT 0x80 /* Enable interrupt for 16-bit cards */ +#define PCI_CB_BRIDGE_CTL_PREFETCH_MEM0 0x100 /* Prefetch enable for both memory regions */ +#define PCI_CB_BRIDGE_CTL_PREFETCH_MEM1 0x200 +#define PCI_CB_BRIDGE_CTL_POST_WRITES 0x400 +#define PCI_CB_SUBSYSTEM_VENDOR_ID 0x40 +#define PCI_CB_SUBSYSTEM_ID 0x42 +#define PCI_CB_LEGACY_MODE_BASE 0x44 /* 16-bit PC Card legacy mode base address (ExCa) */ +/* 0x48-0x7f reserved */ + +/* Capability lists */ +#define PCI_CAP_LIST_ID 0 /* Capability ID */ +#define PCI_CAP_ID_PM 0x01 /* Power Management */ +#define PCI_CAP_ID_AGP 0x02 /* Accelerated Graphics Port */ +#define PCI_CAP_LIST_NEXT 1 /* Next capability in the list */ + +/* Device classes and subclasses */ + +#define PCI_CLASS_NOT_DEFINED 0x0000 +#define PCI_CLASS_NOT_DEFINED_VGA 0x0001 + +#define PCI_BASE_CLASS_STORAGE 0x01 +#define PCI_CLASS_STORAGE_SCSI 0x0100 +#define PCI_CLASS_STORAGE_IDE 0x0101 +#define PCI_CLASS_STORAGE_FLOPPY 0x0102 +#define PCI_CLASS_STORAGE_IPI 0x0103 +#define PCI_CLASS_STORAGE_RAID 0x0104 +#define PCI_CLASS_STORAGE_OTHER 0x0180 + +#define PCI_BASE_CLASS_NETWORK 0x02 +#define PCI_CLASS_NETWORK_ETHERNET 0x0200 +#define PCI_CLASS_NETWORK_TOKEN_RING 0x0201 +#define PCI_CLASS_NETWORK_FDDI 0x0202 +#define PCI_CLASS_NETWORK_ATM 0x0203 +#define PCI_CLASS_NETWORK_OTHER 0x0280 + +#define PCI_BASE_CLASS_DISPLAY 0x03 +#define PCI_CLASS_DISPLAY_VGA 0x0300 +#define PCI_CLASS_DISPLAY_XGA 0x0301 +#define PCI_CLASS_DISPLAY_OTHER 0x0380 + +#define PCI_BASE_CLASS_MULTIMEDIA 0x04 +#define PCI_CLASS_MULTIMEDIA_VIDEO 0x0400 +#define PCI_CLASS_MULTIMEDIA_AUDIO 0x0401 +#define PCI_CLASS_MULTIMEDIA_OTHER 0x0480 + +#define PCI_BASE_CLASS_MEMORY 0x05 +#define PCI_CLASS_MEMORY_RAM 0x0500 +#define PCI_CLASS_MEMORY_FLASH 0x0501 +#define PCI_CLASS_MEMORY_OTHER 0x0580 + +#define PCI_BASE_CLASS_BRIDGE 0x06 +#define PCI_CLASS_BRIDGE_HOST 0x0600 +#define PCI_CLASS_BRIDGE_ISA 0x0601 +#define PCI_CLASS_BRIDGE_EISA 0x0602 +#define PCI_CLASS_BRIDGE_MC 0x0603 +#define PCI_CLASS_BRIDGE_PCI 0x0604 +#define PCI_CLASS_BRIDGE_PCMCIA 0x0605 +#define PCI_CLASS_BRIDGE_NUBUS 0x0606 +#define PCI_CLASS_BRIDGE_CARDBUS 0x0607 +#define PCI_CLASS_BRIDGE_OTHER 0x0680 + +#define PCI_BASE_CLASS_COMMUNICATION 0x07 +#define PCI_CLASS_COMMUNICATION_SERIAL 0x0700 +#define PCI_CLASS_COMMUNICATION_PARALLEL 0x0701 +#define PCI_CLASS_COMMUNICATION_OTHER 0x0780 + +#define PCI_BASE_CLASS_SYSTEM 0x08 +#define PCI_CLASS_SYSTEM_PIC 0x0800 +#define PCI_CLASS_SYSTEM_DMA 0x0801 +#define PCI_CLASS_SYSTEM_TIMER 0x0802 +#define PCI_CLASS_SYSTEM_RTC 0x0803 +#define PCI_CLASS_SYSTEM_OTHER 0x0880 + +#define PCI_BASE_CLASS_INPUT 0x09 +#define PCI_CLASS_INPUT_KEYBOARD 0x0900 +#define PCI_CLASS_INPUT_PEN 0x0901 +#define PCI_CLASS_INPUT_MOUSE 0x0902 +#define PCI_CLASS_INPUT_OTHER 0x0980 + +#define PCI_BASE_CLASS_DOCKING 0x0a +#define PCI_CLASS_DOCKING_GENERIC 0x0a00 +#define PCI_CLASS_DOCKING_OTHER 0x0a01 + +#define PCI_BASE_CLASS_PROCESSOR 0x0b +#define PCI_CLASS_PROCESSOR_386 0x0b00 +#define PCI_CLASS_PROCESSOR_486 0x0b01 +#define PCI_CLASS_PROCESSOR_PENTIUM 0x0b02 +#define PCI_CLASS_PROCESSOR_ALPHA 0x0b10 +#define PCI_CLASS_PROCESSOR_POWERPC 0x0b20 +#define PCI_CLASS_PROCESSOR_CO 0x0b40 + +#define PCI_BASE_CLASS_SERIAL 0x0c +#define PCI_CLASS_SERIAL_FIREWIRE 0x0c00 +#define PCI_CLASS_SERIAL_ACCESS 0x0c01 +#define PCI_CLASS_SERIAL_SSA 0x0c02 +#define PCI_CLASS_SERIAL_USB 0x0c03 +#define PCI_CLASS_SERIAL_FIBER 0x0c04 +#define PCI_CLASS_SERIAL_SMBUS 0x0c05 + +#define PCI_BASE_CLASS_INTELLIGENT 0x0e +#define PCI_CLASS_INTELLIGENT_I2O 0x0e00 + +#define PCI_CLASS_HOT_SWAP_CONTROLLER 0xff00 + +#define PCI_CLASS_OTHERS 0xff + +/* + * Vendor and card ID's: sort these numerically according to vendor + * (and according to card ID within vendor). Send all updates to + * . + */ +#define PCI_VENDOR_ID_COMPAQ 0x0e11 +#define PCI_DEVICE_ID_COMPAQ_TOKENRING 0x0508 +#define PCI_DEVICE_ID_COMPAQ_1280 0x3033 +#define PCI_DEVICE_ID_COMPAQ_TRIFLEX 0x4000 +#define PCI_DEVICE_ID_COMPAQ_6010 0x6010 +#define PCI_DEVICE_ID_COMPAQ_SMART2P 0xae10 +#define PCI_DEVICE_ID_COMPAQ_NETEL100 0xae32 +#define PCI_DEVICE_ID_COMPAQ_NETEL10 0xae34 +#define PCI_DEVICE_ID_COMPAQ_NETFLEX3I 0xae35 +#define PCI_DEVICE_ID_COMPAQ_NETEL100D 0xae40 +#define PCI_DEVICE_ID_COMPAQ_NETEL100PI 0xae43 +#define PCI_DEVICE_ID_COMPAQ_NETEL100I 0xb011 +#define PCI_DEVICE_ID_COMPAQ_THUNDER 0xf130 +#define PCI_DEVICE_ID_COMPAQ_NETFLEX3B 0xf150 + +#define PCI_VENDOR_ID_NCR 0x1000 +#define PCI_DEVICE_ID_NCR_53C810 0x0001 +#define PCI_DEVICE_ID_NCR_53C820 0x0002 +#define PCI_DEVICE_ID_NCR_53C825 0x0003 +#define PCI_DEVICE_ID_NCR_53C815 0x0004 +#define PCI_DEVICE_ID_NCR_53C860 0x0006 +#define PCI_DEVICE_ID_NCR_53C1510D 0x000a +#define PCI_DEVICE_ID_NCR_53C896 0x000b +#define PCI_DEVICE_ID_NCR_53C895 0x000c +#define PCI_DEVICE_ID_NCR_53C885 0x000d +#define PCI_DEVICE_ID_NCR_53C875 0x000f +#define PCI_DEVICE_ID_NCR_53C1510 0x0010 +#define PCI_DEVICE_ID_NCR_53C875J 0x008f + +#define PCI_VENDOR_ID_ATI 0x1002 +#define PCI_DEVICE_ID_ATI_68800 0x4158 +#define PCI_DEVICE_ID_ATI_215CT222 0x4354 +#define PCI_DEVICE_ID_ATI_210888CX 0x4358 +#define PCI_DEVICE_ID_ATI_215GB 0x4742 +#define PCI_DEVICE_ID_ATI_215GD 0x4744 +#define PCI_DEVICE_ID_ATI_215GI 0x4749 +#define PCI_DEVICE_ID_ATI_215GP 0x4750 +#define PCI_DEVICE_ID_ATI_215GQ 0x4751 +#define PCI_DEVICE_ID_ATI_215GT 0x4754 +#define PCI_DEVICE_ID_ATI_215GTB 0x4755 +#define PCI_DEVICE_ID_ATI_210888GX 0x4758 +#define PCI_DEVICE_ID_ATI_RAGE128_LE 0x4c45 +#define PCI_DEVICE_ID_ATI_RAGE128_LF 0x4c46 +#define PCI_DEVICE_ID_ATI_215LG 0x4c47 +#define PCI_DEVICE_ID_ATI_264LT 0x4c54 +#define PCI_DEVICE_ID_ATI_RAGE128_PF 0x5046 +#define PCI_DEVICE_ID_ATI_RAGE128_PR 0x5052 +#define PCI_DEVICE_ID_ATI_RAGE128_RE 0x5245 +#define PCI_DEVICE_ID_ATI_RAGE128_RF 0x5246 +#define PCI_DEVICE_ID_ATI_RAGE128_RK 0x524b +#define PCI_DEVICE_ID_ATI_RAGE128_RL 0x524c +#define PCI_DEVICE_ID_ATI_264VT 0x5654 + +#define PCI_VENDOR_ID_VLSI 0x1004 +#define PCI_DEVICE_ID_VLSI_82C592 0x0005 +#define PCI_DEVICE_ID_VLSI_82C593 0x0006 +#define PCI_DEVICE_ID_VLSI_82C594 0x0007 +#define PCI_DEVICE_ID_VLSI_82C597 0x0009 +#define PCI_DEVICE_ID_VLSI_82C541 0x000c +#define PCI_DEVICE_ID_VLSI_82C543 0x000d +#define PCI_DEVICE_ID_VLSI_82C532 0x0101 +#define PCI_DEVICE_ID_VLSI_82C534 0x0102 +#define PCI_DEVICE_ID_VLSI_82C535 0x0104 +#define PCI_DEVICE_ID_VLSI_82C147 0x0105 +#define PCI_DEVICE_ID_VLSI_VAS96011 0x0702 + +#define PCI_VENDOR_ID_ADL 0x1005 +#define PCI_DEVICE_ID_ADL_2301 0x2301 + +#define PCI_VENDOR_ID_NS 0x100b +#define PCI_DEVICE_ID_NS_87415 0x0002 +#define PCI_DEVICE_ID_NS_87410 0xd001 + +#define PCI_VENDOR_ID_TSENG 0x100c +#define PCI_DEVICE_ID_TSENG_W32P_2 0x3202 +#define PCI_DEVICE_ID_TSENG_W32P_b 0x3205 +#define PCI_DEVICE_ID_TSENG_W32P_c 0x3206 +#define PCI_DEVICE_ID_TSENG_W32P_d 0x3207 +#define PCI_DEVICE_ID_TSENG_ET6000 0x3208 + +#define PCI_VENDOR_ID_WEITEK 0x100e +#define PCI_DEVICE_ID_WEITEK_P9000 0x9001 +#define PCI_DEVICE_ID_WEITEK_P9100 0x9100 + +#define PCI_VENDOR_ID_DEC 0x1011 +#define PCI_DEVICE_ID_DEC_BRD 0x0001 +#define PCI_DEVICE_ID_DEC_TULIP 0x0002 +#define PCI_DEVICE_ID_DEC_TGA 0x0004 +#define PCI_DEVICE_ID_DEC_TULIP_FAST 0x0009 +#define PCI_DEVICE_ID_DEC_TGA2 0x000D +#define PCI_DEVICE_ID_DEC_FDDI 0x000F +#define PCI_DEVICE_ID_DEC_TULIP_PLUS 0x0014 +#define PCI_DEVICE_ID_DEC_21142 0x0019 +#define PCI_DEVICE_ID_DEC_21052 0x0021 +#define PCI_DEVICE_ID_DEC_21150 0x0022 +#define PCI_DEVICE_ID_DEC_21152 0x0024 +#define PCI_DEVICE_ID_DEC_21153 0x0025 +#define PCI_DEVICE_ID_DEC_21154 0x0026 +#define PCI_DEVICE_ID_DEC_21285 0x1065 +#define PCI_DEVICE_ID_DEC_21554 0x0046 +#define PCI_DEVICE_ID_COMPAQ_42XX 0x0046 + +#define PCI_VENDOR_ID_CIRRUS 0x1013 +#define PCI_DEVICE_ID_CIRRUS_7548 0x0038 +#define PCI_DEVICE_ID_CIRRUS_5430 0x00a0 +#define PCI_DEVICE_ID_CIRRUS_5434_4 0x00a4 +#define PCI_DEVICE_ID_CIRRUS_5434_8 0x00a8 +#define PCI_DEVICE_ID_CIRRUS_5436 0x00ac +#define PCI_DEVICE_ID_CIRRUS_5446 0x00b8 +#define PCI_DEVICE_ID_CIRRUS_5480 0x00bc +#define PCI_DEVICE_ID_CIRRUS_5464 0x00d4 +#define PCI_DEVICE_ID_CIRRUS_5465 0x00d6 +#define PCI_DEVICE_ID_CIRRUS_6729 0x1100 +#define PCI_DEVICE_ID_CIRRUS_6832 0x1110 +#define PCI_DEVICE_ID_CIRRUS_7542 0x1200 +#define PCI_DEVICE_ID_CIRRUS_7543 0x1202 +#define PCI_DEVICE_ID_CIRRUS_7541 0x1204 + +#define PCI_VENDOR_ID_IBM 0x1014 +#define PCI_DEVICE_ID_IBM_FIRE_CORAL 0x000a +#define PCI_DEVICE_ID_IBM_TR 0x0018 +#define PCI_DEVICE_ID_IBM_82G2675 0x001d +#define PCI_DEVICE_ID_IBM_MCA 0x0020 +#define PCI_DEVICE_ID_IBM_82351 0x0022 +#define PCI_DEVICE_ID_IBM_PYTHON 0x002d +#define PCI_DEVICE_ID_IBM_SERVERAID 0x002e +#define PCI_DEVICE_ID_IBM_TR_WAKE 0x003e +#define PCI_DEVICE_ID_IBM_MPIC 0x0046 +#define PCI_DEVICE_ID_IBM_3780IDSP 0x007d +#define PCI_DEVICE_ID_IBM_MPIC_2 0xffff + +#define PCI_VENDOR_ID_WD 0x101c +#define PCI_DEVICE_ID_WD_7197 0x3296 + +#define PCI_VENDOR_ID_AMD 0x1022 +#define PCI_DEVICE_ID_AMD_LANCE 0x2000 +#define PCI_DEVICE_ID_AMD_LANCE_HOME 0x2001 +#define PCI_DEVICE_ID_AMD_SCSI 0x2020 + +#define PCI_VENDOR_ID_TRIDENT 0x1023 +#define PCI_DEVICE_ID_TRIDENT_9397 0x9397 +#define PCI_DEVICE_ID_TRIDENT_9420 0x9420 +#define PCI_DEVICE_ID_TRIDENT_9440 0x9440 +#define PCI_DEVICE_ID_TRIDENT_9660 0x9660 +#define PCI_DEVICE_ID_TRIDENT_9750 0x9750 + +#define PCI_VENDOR_ID_AI 0x1025 +#define PCI_DEVICE_ID_AI_M1435 0x1435 + +#define PCI_VENDOR_ID_MATROX 0x102B +#define PCI_DEVICE_ID_MATROX_MGA_2 0x0518 +#define PCI_DEVICE_ID_MATROX_MIL 0x0519 +#define PCI_DEVICE_ID_MATROX_MYS 0x051A +#define PCI_DEVICE_ID_MATROX_MIL_2 0x051b +#define PCI_DEVICE_ID_MATROX_MIL_2_AGP 0x051f +#define PCI_DEVICE_ID_MATROX_G200_PCI 0x0520 +#define PCI_DEVICE_ID_MATROX_G200_AGP 0x0521 +#define PCI_DEVICE_ID_MATROX_MGA_IMP 0x0d10 +#define PCI_DEVICE_ID_MATROX_G100_MM 0x1000 +#define PCI_DEVICE_ID_MATROX_G100_AGP 0x1001 + +#define PCI_VENDOR_ID_CT 0x102c +#define PCI_DEVICE_ID_CT_65545 0x00d8 +#define PCI_DEVICE_ID_CT_65548 0x00dc +#define PCI_DEVICE_ID_CT_65550 0x00e0 +#define PCI_DEVICE_ID_CT_65554 0x00e4 +#define PCI_DEVICE_ID_CT_65555 0x00e5 + +#define PCI_VENDOR_ID_MIRO 0x1031 +#define PCI_DEVICE_ID_MIRO_36050 0x5601 + +#define PCI_VENDOR_ID_NEC 0x1033 +#define PCI_DEVICE_ID_NEC_PCX2 0x0046 + +#define PCI_VENDOR_ID_FD 0x1036 +#define PCI_DEVICE_ID_FD_36C70 0x0000 + +#define PCI_VENDOR_ID_SI 0x1039 +#define PCI_DEVICE_ID_SI_5591_AGP 0x0001 +#define PCI_DEVICE_ID_SI_6202 0x0002 +#define PCI_DEVICE_ID_SI_503 0x0008 +#define PCI_DEVICE_ID_SI_ACPI 0x0009 +#define PCI_DEVICE_ID_SI_5597_VGA 0x0200 +#define PCI_DEVICE_ID_SI_6205 0x0205 +#define PCI_DEVICE_ID_SI_501 0x0406 +#define PCI_DEVICE_ID_SI_496 0x0496 +#define PCI_DEVICE_ID_SI_601 0x0601 +#define PCI_DEVICE_ID_SI_5107 0x5107 +#define PCI_DEVICE_ID_SI_5511 0x5511 +#define PCI_DEVICE_ID_SI_5513 0x5513 +#define PCI_DEVICE_ID_SI_5571 0x5571 +#define PCI_DEVICE_ID_SI_5591 0x5591 +#define PCI_DEVICE_ID_SI_5597 0x5597 +#define PCI_DEVICE_ID_SI_7001 0x7001 + +#define PCI_VENDOR_ID_HP 0x103c +#define PCI_DEVICE_ID_HP_J2585A 0x1030 +#define PCI_DEVICE_ID_HP_J2585B 0x1031 + +#define PCI_VENDOR_ID_PCTECH 0x1042 +#define PCI_DEVICE_ID_PCTECH_RZ1000 0x1000 +#define PCI_DEVICE_ID_PCTECH_RZ1001 0x1001 +#define PCI_DEVICE_ID_PCTECH_SAMURAI_0 0x3000 +#define PCI_DEVICE_ID_PCTECH_SAMURAI_1 0x3010 +#define PCI_DEVICE_ID_PCTECH_SAMURAI_IDE 0x3020 + +#define PCI_VENDOR_ID_DPT 0x1044 +#define PCI_DEVICE_ID_DPT 0xa400 + +#define PCI_VENDOR_ID_OPTI 0x1045 +#define PCI_DEVICE_ID_OPTI_92C178 0xc178 +#define PCI_DEVICE_ID_OPTI_82C557 0xc557 +#define PCI_DEVICE_ID_OPTI_82C558 0xc558 +#define PCI_DEVICE_ID_OPTI_82C621 0xc621 +#define PCI_DEVICE_ID_OPTI_82C700 0xc700 +#define PCI_DEVICE_ID_OPTI_82C701 0xc701 +#define PCI_DEVICE_ID_OPTI_82C814 0xc814 +#define PCI_DEVICE_ID_OPTI_82C822 0xc822 +#define PCI_DEVICE_ID_OPTI_82C861 0xc861 +#define PCI_DEVICE_ID_OPTI_82C825 0xd568 + +#define PCI_VENDOR_ID_SGS 0x104a +#define PCI_DEVICE_ID_SGS_2000 0x0008 +#define PCI_DEVICE_ID_SGS_1764 0x0009 + +#define PCI_VENDOR_ID_BUSLOGIC 0x104B +#define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC 0x0140 +#define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER 0x1040 +#define PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT 0x8130 + +#define PCI_VENDOR_ID_TI 0x104c +#define PCI_DEVICE_ID_TI_TVP4010 0x3d04 +#define PCI_DEVICE_ID_TI_TVP4020 0x3d07 +#define PCI_DEVICE_ID_TI_PCI1130 0xac12 +#define PCI_DEVICE_ID_TI_PCI1031 0xac13 +#define PCI_DEVICE_ID_TI_PCI1131 0xac15 +#define PCI_DEVICE_ID_TI_PCI1250 0xac16 +#define PCI_DEVICE_ID_TI_PCI1220 0xac17 + +#define PCI_VENDOR_ID_OAK 0x104e +#define PCI_DEVICE_ID_OAK_OTI107 0x0107 + +/* Winbond have two vendor IDs! See 0x10ad as well */ +#define PCI_VENDOR_ID_WINBOND2 0x1050 +#define PCI_DEVICE_ID_WINBOND2_89C940 0x0940 + +#define PCI_VENDOR_ID_MOTOROLA 0x1057 +#define PCI_VENDOR_ID_MOTOROLA_OOPS 0x1507 +#define PCI_DEVICE_ID_MOTOROLA_MPC105 0x0001 +#define PCI_DEVICE_ID_MOTOROLA_MPC106 0x0002 +#define PCI_DEVICE_ID_MOTOROLA_RAVEN 0x4801 +#define PCI_DEVICE_ID_MOTOROLA_FALCON 0x4802 +#define PCI_DEVICE_ID_MOTOROLA_CPX8216 0x4806 + +#define PCI_VENDOR_ID_PROMISE 0x105a +#define PCI_DEVICE_ID_PROMISE_20246 0x4d33 +#define PCI_DEVICE_ID_PROMISE_5300 0x5300 + +#define PCI_VENDOR_ID_N9 0x105d +#define PCI_DEVICE_ID_N9_I128 0x2309 +#define PCI_DEVICE_ID_N9_I128_2 0x2339 +#define PCI_DEVICE_ID_N9_I128_T2R 0x493d + +#define PCI_VENDOR_ID_UMC 0x1060 +#define PCI_DEVICE_ID_UMC_UM8673F 0x0101 +#define PCI_DEVICE_ID_UMC_UM8891A 0x0891 +#define PCI_DEVICE_ID_UMC_UM8886BF 0x673a +#define PCI_DEVICE_ID_UMC_UM8886A 0x886a +#define PCI_DEVICE_ID_UMC_UM8881F 0x8881 +#define PCI_DEVICE_ID_UMC_UM8886F 0x8886 +#define PCI_DEVICE_ID_UMC_UM9017F 0x9017 +#define PCI_DEVICE_ID_UMC_UM8886N 0xe886 +#define PCI_DEVICE_ID_UMC_UM8891N 0xe891 + +#define PCI_VENDOR_ID_X 0x1061 +#define PCI_DEVICE_ID_X_AGX016 0x0001 + +#define PCI_VENDOR_ID_PICOP 0x1066 +#define PCI_DEVICE_ID_PICOP_PT86C52X 0x0001 +#define PCI_DEVICE_ID_PICOP_PT80C524 0x8002 + +#define PCI_VENDOR_ID_MYLEX 0x1069 +#define PCI_DEVICE_ID_MYLEX_DAC960_P 0x0001 +#define PCI_DEVICE_ID_MYLEX_DAC960_PD 0x0002 +#define PCI_DEVICE_ID_MYLEX_DAC960_PG 0x0010 +#define PCI_DEVICE_ID_MYLEX_DAC960_LA 0x0020 +#define PCI_DEVICE_ID_MYLEX_DAC960_LP 0x0050 +#define PCI_DEVICE_ID_MYLEX_DAC960_BA 0xBA56 + +#define PCI_VENDOR_ID_APPLE 0x106b +#define PCI_DEVICE_ID_APPLE_BANDIT 0x0001 +#define PCI_DEVICE_ID_APPLE_GC 0x0002 +#define PCI_DEVICE_ID_APPLE_HYDRA 0x000e + +#define PCI_VENDOR_ID_NEXGEN 0x1074 +#define PCI_DEVICE_ID_NEXGEN_82C501 0x4e78 + +#define PCI_VENDOR_ID_QLOGIC 0x1077 +#define PCI_DEVICE_ID_QLOGIC_ISP1020 0x1020 +#define PCI_DEVICE_ID_QLOGIC_ISP1022 0x1022 +#define PCI_DEVICE_ID_QLOGIC_ISP2100 0x2100 +#define PCI_DEVICE_ID_QLOGIC_ISP2200 0x2200 + +#define PCI_VENDOR_ID_CYRIX 0x1078 +#define PCI_DEVICE_ID_CYRIX_5510 0x0000 +#define PCI_DEVICE_ID_CYRIX_PCI_MASTER 0x0001 +#define PCI_DEVICE_ID_CYRIX_5520 0x0002 +#define PCI_DEVICE_ID_CYRIX_5530_LEGACY 0x0100 +#define PCI_DEVICE_ID_CYRIX_5530_SMI 0x0101 +#define PCI_DEVICE_ID_CYRIX_5530_IDE 0x0102 +#define PCI_DEVICE_ID_CYRIX_5530_AUDIO 0x0103 +#define PCI_DEVICE_ID_CYRIX_5530_VIDEO 0x0104 + +#define PCI_VENDOR_ID_LEADTEK 0x107d +#define PCI_DEVICE_ID_LEADTEK_805 0x0000 + +#define PCI_VENDOR_ID_CONTAQ 0x1080 +#define PCI_DEVICE_ID_CONTAQ_82C599 0x0600 +#define PCI_DEVICE_ID_CONTAQ_82C693 0xc693 + +#define PCI_VENDOR_ID_FOREX 0x1083 + +#define PCI_VENDOR_ID_OLICOM 0x108d +#define PCI_DEVICE_ID_OLICOM_OC3136 0x0001 +#define PCI_DEVICE_ID_OLICOM_OC2315 0x0011 +#define PCI_DEVICE_ID_OLICOM_OC2325 0x0012 +#define PCI_DEVICE_ID_OLICOM_OC2183 0x0013 +#define PCI_DEVICE_ID_OLICOM_OC2326 0x0014 +#define PCI_DEVICE_ID_OLICOM_OC6151 0x0021 + +#define PCI_VENDOR_ID_SUN 0x108e +#define PCI_DEVICE_ID_SUN_EBUS 0x1000 +#define PCI_DEVICE_ID_SUN_HAPPYMEAL 0x1001 +#define PCI_DEVICE_ID_SUN_SIMBA 0x5000 +#define PCI_DEVICE_ID_SUN_PBM 0x8000 +#define PCI_DEVICE_ID_SUN_SABRE 0xa000 + +#define PCI_VENDOR_ID_CMD 0x1095 +#define PCI_DEVICE_ID_CMD_640 0x0640 +#define PCI_DEVICE_ID_CMD_643 0x0643 +#define PCI_DEVICE_ID_CMD_646 0x0646 +#define PCI_DEVICE_ID_CMD_647 0x0647 +#define PCI_DEVICE_ID_CMD_670 0x0670 + +#define PCI_VENDOR_ID_VISION 0x1098 +#define PCI_DEVICE_ID_VISION_QD8500 0x0001 +#define PCI_DEVICE_ID_VISION_QD8580 0x0002 + +#define PCI_VENDOR_ID_BROOKTREE 0x109e +#define PCI_DEVICE_ID_BROOKTREE_848 0x0350 +#define PCI_DEVICE_ID_BROOKTREE_849A 0x0351 +#define PCI_DEVICE_ID_BROOKTREE_878_1 0x036e +#define PCI_DEVICE_ID_BROOKTREE_878 0x0878 +#define PCI_DEVICE_ID_BROOKTREE_8474 0x8474 + +#define PCI_VENDOR_ID_SIERRA 0x10a8 +#define PCI_DEVICE_ID_SIERRA_STB 0x0000 + +#define PCI_VENDOR_ID_ACC 0x10aa +#define PCI_DEVICE_ID_ACC_2056 0x0000 + +#define PCI_VENDOR_ID_WINBOND 0x10ad +#define PCI_DEVICE_ID_WINBOND_83769 0x0001 +#define PCI_DEVICE_ID_WINBOND_82C105 0x0105 +#define PCI_DEVICE_ID_WINBOND_83C553 0x0565 + +#define PCI_VENDOR_ID_DATABOOK 0x10b3 +#define PCI_DEVICE_ID_DATABOOK_87144 0xb106 + +#define PCI_VENDOR_ID_PLX 0x10b5 +#define PCI_DEVICE_ID_PLX_9050 0x9050 +#define PCI_DEVICE_ID_PLX_9060 0x9060 +#define PCI_DEVICE_ID_PLX_9060ES 0x906E +#define PCI_DEVICE_ID_PLX_9060SD 0x906D +#define PCI_DEVICE_ID_PLX_9080 0x9080 + +#define PCI_VENDOR_ID_MADGE 0x10b6 +#define PCI_DEVICE_ID_MADGE_MK2 0x0002 +#define PCI_DEVICE_ID_MADGE_C155S 0x1001 + +#define PCI_VENDOR_ID_3COM 0x10b7 +#define PCI_DEVICE_ID_3COM_3C985 0x0001 +#define PCI_DEVICE_ID_3COM_3C339 0x3390 +#define PCI_DEVICE_ID_3COM_3C590 0x5900 +#define PCI_DEVICE_ID_3COM_3C595TX 0x5950 +#define PCI_DEVICE_ID_3COM_3C595T4 0x5951 +#define PCI_DEVICE_ID_3COM_3C595MII 0x5952 +#define PCI_DEVICE_ID_3COM_3C900TPO 0x9000 +#define PCI_DEVICE_ID_3COM_3C900COMBO 0x9001 +#define PCI_DEVICE_ID_3COM_3C905TX 0x9050 +#define PCI_DEVICE_ID_3COM_3C905T4 0x9051 +#define PCI_DEVICE_ID_3COM_3C905B_TX 0x9055 + +#define PCI_VENDOR_ID_SMC 0x10b8 +#define PCI_DEVICE_ID_SMC_EPIC100 0x0005 + +#define PCI_VENDOR_ID_AL 0x10b9 +#define PCI_DEVICE_ID_AL_M1445 0x1445 +#define PCI_DEVICE_ID_AL_M1449 0x1449 +#define PCI_DEVICE_ID_AL_M1451 0x1451 +#define PCI_DEVICE_ID_AL_M1461 0x1461 +#define PCI_DEVICE_ID_AL_M1489 0x1489 +#define PCI_DEVICE_ID_AL_M1511 0x1511 +#define PCI_DEVICE_ID_AL_M1513 0x1513 +#define PCI_DEVICE_ID_AL_M1521 0x1521 +#define PCI_DEVICE_ID_AL_M1523 0x1523 +#define PCI_DEVICE_ID_AL_M1531 0x1531 +#define PCI_DEVICE_ID_AL_M1533 0x1533 +#define PCI_DEVICE_ID_AL_M3307 0x3307 +#define PCI_DEVICE_ID_AL_M4803 0x5215 +#define PCI_DEVICE_ID_AL_M5219 0x5219 +#define PCI_DEVICE_ID_AL_M5229 0x5229 +#define PCI_DEVICE_ID_AL_M5237 0x5237 +#define PCI_DEVICE_ID_AL_M7101 0x7101 + +#define PCI_VENDOR_ID_MITSUBISHI 0x10ba + +#define PCI_VENDOR_ID_SURECOM 0x10bd +#define PCI_DEVICE_ID_SURECOM_NE34 0x0e34 + +#define PCI_VENDOR_ID_NEOMAGIC 0x10c8 +#define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_NM2070 0x0001 +#define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_128V 0x0002 +#define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_128ZV 0x0003 +#define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_NM2160 0x0004 +#define PCI_DEVICE_ID_NEOMAGIC_MAGICMEDIA_256AV 0x0005 +#define PCI_DEVICE_ID_NEOMAGIC_MAGICGRAPH_128ZVPLUS 0x0083 + +#define PCI_VENDOR_ID_ASP 0x10cd +#define PCI_DEVICE_ID_ASP_ABP940 0x1200 +#define PCI_DEVICE_ID_ASP_ABP940U 0x1300 +#define PCI_DEVICE_ID_ASP_ABP940UW 0x2300 + +#define PCI_VENDOR_ID_MACRONIX 0x10d9 +#define PCI_DEVICE_ID_MACRONIX_MX98713 0x0512 +#define PCI_DEVICE_ID_MACRONIX_MX987x5 0x0531 + +#define PCI_VENDOR_ID_CERN 0x10dc +#define PCI_DEVICE_ID_CERN_SPSB_PMC 0x0001 +#define PCI_DEVICE_ID_CERN_SPSB_PCI 0x0002 +#define PCI_DEVICE_ID_CERN_HIPPI_DST 0x0021 +#define PCI_DEVICE_ID_CERN_HIPPI_SRC 0x0022 + +#define PCI_VENDOR_ID_NVIDIA 0x10de + +#define PCI_VENDOR_ID_IMS 0x10e0 +#define PCI_DEVICE_ID_IMS_8849 0x8849 + +#define PCI_VENDOR_ID_TEKRAM2 0x10e1 +#define PCI_DEVICE_ID_TEKRAM2_690c 0x690c + +#define PCI_VENDOR_ID_TUNDRA 0x10e3 +#define PCI_DEVICE_ID_TUNDRA_CA91C042 0x0000 + +#define PCI_VENDOR_ID_AMCC 0x10e8 +#define PCI_DEVICE_ID_AMCC_MYRINET 0x8043 +#define PCI_DEVICE_ID_AMCC_PARASTATION 0x8062 +#define PCI_DEVICE_ID_AMCC_S5933 0x807d +#define PCI_DEVICE_ID_AMCC_S5933_HEPC3 0x809c + +#define PCI_VENDOR_ID_INTERG 0x10ea +#define PCI_DEVICE_ID_INTERG_1680 0x1680 +#define PCI_DEVICE_ID_INTERG_1682 0x1682 + +#define PCI_VENDOR_ID_REALTEK 0x10ec +#define PCI_DEVICE_ID_REALTEK_8029 0x8029 +#define PCI_DEVICE_ID_REALTEK_8129 0x8129 +#define PCI_DEVICE_ID_REALTEK_8139 0x8139 + +#define PCI_VENDOR_ID_TRUEVISION 0x10fa +#define PCI_DEVICE_ID_TRUEVISION_T1000 0x000c + +#define PCI_VENDOR_ID_INIT 0x1101 +#define PCI_DEVICE_ID_INIT_320P 0x9100 +#define PCI_DEVICE_ID_INIT_360P 0x9500 + +#define PCI_VENDOR_ID_TTI 0x1103 +#define PCI_DEVICE_ID_TTI_HPT343 0x0003 + +#define PCI_VENDOR_ID_VIA 0x1106 +#define PCI_DEVICE_ID_VIA_82C505 0x0505 +#define PCI_DEVICE_ID_VIA_82C561 0x0561 +#define PCI_DEVICE_ID_VIA_82C586_1 0x0571 +#define PCI_DEVICE_ID_VIA_82C576 0x0576 +#define PCI_DEVICE_ID_VIA_82C585 0x0585 +#define PCI_DEVICE_ID_VIA_82C586_0 0x0586 +#define PCI_DEVICE_ID_VIA_82C595 0x0595 +#define PCI_DEVICE_ID_VIA_82C596_0 0x0596 +#define PCI_DEVICE_ID_VIA_82C597_0 0x0597 +#define PCI_DEVICE_ID_VIA_82C598_0 0x0598 +#define PCI_DEVICE_ID_VIA_82C926 0x0926 +#define PCI_DEVICE_ID_VIA_82C416 0x1571 +#define PCI_DEVICE_ID_VIA_82C595_97 0x1595 +#define PCI_DEVICE_ID_VIA_82C586_2 0x3038 +#define PCI_DEVICE_ID_VIA_82C586_3 0x3040 +#define PCI_DEVICE_ID_VIA_82C686_5 0x3058 +#define PCI_DEVICE_ID_VIA_86C100A 0x6100 +#define PCI_DEVICE_ID_VIA_82C597_1 0x8597 +#define PCI_DEVICE_ID_VIA_82C598_1 0x8598 + +#define PCI_VENDOR_ID_SMC2 0x1113 +#define PCI_DEVICE_ID_SMC2_1211TX 0x1211 + +#define PCI_VENDOR_ID_VORTEX 0x1119 +#define PCI_DEVICE_ID_VORTEX_GDT60x0 0x0000 +#define PCI_DEVICE_ID_VORTEX_GDT6000B 0x0001 +#define PCI_DEVICE_ID_VORTEX_GDT6x10 0x0002 +#define PCI_DEVICE_ID_VORTEX_GDT6x20 0x0003 +#define PCI_DEVICE_ID_VORTEX_GDT6530 0x0004 +#define PCI_DEVICE_ID_VORTEX_GDT6550 0x0005 +#define PCI_DEVICE_ID_VORTEX_GDT6x17 0x0006 +#define PCI_DEVICE_ID_VORTEX_GDT6x27 0x0007 +#define PCI_DEVICE_ID_VORTEX_GDT6537 0x0008 +#define PCI_DEVICE_ID_VORTEX_GDT6557 0x0009 +#define PCI_DEVICE_ID_VORTEX_GDT6x15 0x000a +#define PCI_DEVICE_ID_VORTEX_GDT6x25 0x000b +#define PCI_DEVICE_ID_VORTEX_GDT6535 0x000c +#define PCI_DEVICE_ID_VORTEX_GDT6555 0x000d +#define PCI_DEVICE_ID_VORTEX_GDT6x17RP 0x0100 +#define PCI_DEVICE_ID_VORTEX_GDT6x27RP 0x0101 +#define PCI_DEVICE_ID_VORTEX_GDT6537RP 0x0102 +#define PCI_DEVICE_ID_VORTEX_GDT6557RP 0x0103 +#define PCI_DEVICE_ID_VORTEX_GDT6x11RP 0x0104 +#define PCI_DEVICE_ID_VORTEX_GDT6x21RP 0x0105 +#define PCI_DEVICE_ID_VORTEX_GDT6x17RP1 0x0110 +#define PCI_DEVICE_ID_VORTEX_GDT6x27RP1 0x0111 +#define PCI_DEVICE_ID_VORTEX_GDT6537RP1 0x0112 +#define PCI_DEVICE_ID_VORTEX_GDT6557RP1 0x0113 +#define PCI_DEVICE_ID_VORTEX_GDT6x11RP1 0x0114 +#define PCI_DEVICE_ID_VORTEX_GDT6x21RP1 0x0115 +#define PCI_DEVICE_ID_VORTEX_GDT6x17RP2 0x0120 +#define PCI_DEVICE_ID_VORTEX_GDT6x27RP2 0x0121 +#define PCI_DEVICE_ID_VORTEX_GDT6537RP2 0x0122 +#define PCI_DEVICE_ID_VORTEX_GDT6557RP2 0x0123 +#define PCI_DEVICE_ID_VORTEX_GDT6x11RP2 0x0124 +#define PCI_DEVICE_ID_VORTEX_GDT6x21RP2 0x0125 + +#define PCI_VENDOR_ID_EF 0x111a +#define PCI_DEVICE_ID_EF_ATM_FPGA 0x0000 +#define PCI_DEVICE_ID_EF_ATM_ASIC 0x0002 + +#define PCI_VENDOR_ID_FORE 0x1127 +#define PCI_DEVICE_ID_FORE_PCA200PC 0x0210 +#define PCI_DEVICE_ID_FORE_PCA200E 0x0300 + +#define PCI_VENDOR_ID_IMAGINGTECH 0x112f +#define PCI_DEVICE_ID_IMAGINGTECH_ICPCI 0x0000 + +#define PCI_VENDOR_ID_PHILIPS 0x1131 +#define PCI_DEVICE_ID_PHILIPS_SAA7145 0x7145 +#define PCI_DEVICE_ID_PHILIPS_SAA7146 0x7146 + +#define PCI_VENDOR_ID_CYCLONE 0x113c +#define PCI_DEVICE_ID_CYCLONE_SDK 0x0001 + +#define PCI_VENDOR_ID_ALLIANCE 0x1142 +#define PCI_DEVICE_ID_ALLIANCE_PROMOTIO 0x3210 +#define PCI_DEVICE_ID_ALLIANCE_PROVIDEO 0x6422 +#define PCI_DEVICE_ID_ALLIANCE_AT24 0x6424 +#define PCI_DEVICE_ID_ALLIANCE_AT3D 0x643d + +#define PCI_VENDOR_ID_SYSKONNECT 0x1148 +#define PCI_DEVICE_ID_SYSKONNECT_FP 0x4000 +#define PCI_DEVICE_ID_SYSKONNECT_TR 0x4200 +#define PCI_DEVICE_ID_SYSKONNECT_GE 0x4300 + +#define PCI_VENDOR_ID_VMIC 0x114a +#define PCI_DEVICE_ID_VMIC_VME 0x7587 + +#define PCI_VENDOR_ID_DIGI 0x114f +#define PCI_DEVICE_ID_DIGI_EPC 0x0002 +#define PCI_DEVICE_ID_DIGI_RIGHTSWITCH 0x0003 +#define PCI_DEVICE_ID_DIGI_XEM 0x0004 +#define PCI_DEVICE_ID_DIGI_XR 0x0005 +#define PCI_DEVICE_ID_DIGI_CX 0x0006 +#define PCI_DEVICE_ID_DIGI_XRJ 0x0009 +#define PCI_DEVICE_ID_DIGI_EPCJ 0x000a +#define PCI_DEVICE_ID_DIGI_XR_920 0x0027 + +#define PCI_VENDOR_ID_MUTECH 0x1159 +#define PCI_DEVICE_ID_MUTECH_MV1000 0x0001 + +#define PCI_VENDOR_ID_RENDITION 0x1163 +#define PCI_DEVICE_ID_RENDITION_VERITE 0x0001 +#define PCI_DEVICE_ID_RENDITION_VERITE2100 0x2000 + +#define PCI_VENDOR_ID_SERVERWORKS 0x1166 +#define PCI_DEVICE_ID_SERVERWORKS_HE 0x0008 +#define PCI_DEVICE_ID_SERVERWORKS_LE 0x0009 +#define PCI_DEVICE_ID_SERVERWORKS_CIOB30 0x0010 +#define PCI_DEVICE_ID_SERVERWORKS_CMIC_HE 0x0011 +#define PCI_DEVICE_ID_SERVERWORKS_CSB5 0x0201 + +#define PCI_VENDOR_ID_SBE 0x1176 +#define PCI_DEVICE_ID_SBE_WANXL100 0x0301 +#define PCI_DEVICE_ID_SBE_WANXL200 0x0302 +#define PCI_DEVICE_ID_SBE_WANXL400 0x0104 + +#define PCI_VENDOR_ID_TOSHIBA 0x1179 +#define PCI_DEVICE_ID_TOSHIBA_601 0x0601 +#define PCI_DEVICE_ID_TOSHIBA_TOPIC95 0x060a +#define PCI_DEVICE_ID_TOSHIBA_TOPIC97 0x060f + +#define PCI_VENDOR_ID_RICOH 0x1180 +#define PCI_DEVICE_ID_RICOH_RL5C465 0x0465 +#define PCI_DEVICE_ID_RICOH_RL5C466 0x0466 +#define PCI_DEVICE_ID_RICOH_RL5C475 0x0475 +#define PCI_DEVICE_ID_RICOH_RL5C478 0x0478 + +#define PCI_VENDOR_ID_ARTOP 0x1191 +#define PCI_DEVICE_ID_ARTOP_ATP8400 0x0004 +#define PCI_DEVICE_ID_ARTOP_ATP850UF 0x0005 + +#define PCI_VENDOR_ID_ZEITNET 0x1193 +#define PCI_DEVICE_ID_ZEITNET_1221 0x0001 +#define PCI_DEVICE_ID_ZEITNET_1225 0x0002 + +#define PCI_VENDOR_ID_OMEGA 0x119b +#define PCI_DEVICE_ID_OMEGA_82C092G 0x1221 + +#define PCI_VENDOR_ID_GALILEO 0x11ab +#define PCI_DEVICE_ID_GALILEO_GT64011 0x4146 + +#define PCI_VENDOR_ID_LITEON 0x11ad +#define PCI_DEVICE_ID_LITEON_LNE100TX 0x0002 + +#define PCI_VENDOR_ID_NP 0x11bc +#define PCI_DEVICE_ID_NP_PCI_FDDI 0x0001 + +#define PCI_VENDOR_ID_ATT 0x11c1 +#define PCI_DEVICE_ID_ATT_L56XMF 0x0440 +#define PCI_DEVICE_ID_ATT_L56DVP 0x0480 + +#define PCI_VENDOR_ID_SPECIALIX 0x11cb +#define PCI_DEVICE_ID_SPECIALIX_IO8 0x2000 +#define PCI_DEVICE_ID_SPECIALIX_XIO 0x4000 +#define PCI_DEVICE_ID_SPECIALIX_RIO 0x8000 + +#define PCI_VENDOR_ID_AURAVISION 0x11d1 +#define PCI_DEVICE_ID_AURAVISION_VXP524 0x01f7 + +#define PCI_VENDOR_ID_IKON 0x11d5 +#define PCI_DEVICE_ID_IKON_10115 0x0115 +#define PCI_DEVICE_ID_IKON_10117 0x0117 + +#define PCI_VENDOR_ID_ZORAN 0x11de +#define PCI_DEVICE_ID_ZORAN_36057 0x6057 +#define PCI_DEVICE_ID_ZORAN_36120 0x6120 + +#define PCI_VENDOR_ID_KINETIC 0x11f4 +#define PCI_DEVICE_ID_KINETIC_2915 0x2915 + +#define PCI_VENDOR_ID_COMPEX 0x11f6 +#define PCI_DEVICE_ID_COMPEX_ENET100VG4 0x0112 +#define PCI_DEVICE_ID_COMPEX_RL2000 0x1401 + +#define PCI_VENDOR_ID_RP 0x11fe +#define PCI_DEVICE_ID_RP32INTF 0x0001 +#define PCI_DEVICE_ID_RP8INTF 0x0002 +#define PCI_DEVICE_ID_RP16INTF 0x0003 +#define PCI_DEVICE_ID_RP4QUAD 0x0004 +#define PCI_DEVICE_ID_RP8OCTA 0x0005 +#define PCI_DEVICE_ID_RP8J 0x0006 +#define PCI_DEVICE_ID_RPP4 0x000A +#define PCI_DEVICE_ID_RPP8 0x000B +#define PCI_DEVICE_ID_RP8M 0x000C + +#define PCI_VENDOR_ID_CYCLADES 0x120e +#define PCI_DEVICE_ID_CYCLOM_Y_Lo 0x0100 +#define PCI_DEVICE_ID_CYCLOM_Y_Hi 0x0101 +#define PCI_DEVICE_ID_CYCLOM_4Y_Lo 0x0102 +#define PCI_DEVICE_ID_CYCLOM_4Y_Hi 0x0103 +#define PCI_DEVICE_ID_CYCLOM_8Y_Lo 0x0104 +#define PCI_DEVICE_ID_CYCLOM_8Y_Hi 0x0105 +#define PCI_DEVICE_ID_CYCLOM_Z_Lo 0x0200 +#define PCI_DEVICE_ID_CYCLOM_Z_Hi 0x0201 +#define PCI_DEVICE_ID_PC300_RX_2 0x0300 +#define PCI_DEVICE_ID_PC300_RX_1 0x0301 +#define PCI_DEVICE_ID_PC300_TE_2 0x0310 +#define PCI_DEVICE_ID_PC300_TE_1 0x0311 + +#define PCI_VENDOR_ID_ESSENTIAL 0x120f +#define PCI_DEVICE_ID_ESSENTIAL_ROADRUNNER 0x0001 + +#define PCI_VENDOR_ID_O2 0x1217 +#define PCI_DEVICE_ID_O2_6729 0x6729 +#define PCI_DEVICE_ID_O2_6730 0x673a +#define PCI_DEVICE_ID_O2_6832 0x6832 +#define PCI_DEVICE_ID_O2_6836 0x6836 + +#define PCI_VENDOR_ID_3DFX 0x121a +#define PCI_DEVICE_ID_3DFX_VOODOO 0x0001 +#define PCI_DEVICE_ID_3DFX_VOODOO2 0x0002 +#define PCI_DEVICE_ID_3DFX_BANSHEE 0x0003 + +#define PCI_VENDOR_ID_SIGMADES 0x1236 +#define PCI_DEVICE_ID_SIGMADES_6425 0x6401 + +#define PCI_VENDOR_ID_CCUBE 0x123f + +#define PCI_VENDOR_ID_AVM 0x1244 +#define PCI_DEVICE_ID_AVM_A1 0x0a00 + +#define PCI_VENDOR_ID_DIPIX 0x1246 + +#define PCI_VENDOR_ID_STALLION 0x124d +#define PCI_DEVICE_ID_STALLION_ECHPCI832 0x0000 +#define PCI_DEVICE_ID_STALLION_ECHPCI864 0x0002 +#define PCI_DEVICE_ID_STALLION_EIOPCI 0x0003 + +#define PCI_VENDOR_ID_OPTIBASE 0x1255 +#define PCI_DEVICE_ID_OPTIBASE_FORGE 0x1110 +#define PCI_DEVICE_ID_OPTIBASE_FUSION 0x1210 +#define PCI_DEVICE_ID_OPTIBASE_VPLEX 0x2110 +#define PCI_DEVICE_ID_OPTIBASE_VPLEXCC 0x2120 +#define PCI_DEVICE_ID_OPTIBASE_VQUEST 0x2130 + +#define PCI_VENDOR_ID_SATSAGEM 0x1267 +#define PCI_DEVICE_ID_SATSAGEM_PCR2101 0x5352 +#define PCI_DEVICE_ID_SATSAGEM_TELSATTURBO 0x5a4b + +#define PCI_VENDOR_ID_HUGHES 0x1273 +#define PCI_DEVICE_ID_HUGHES_DIRECPC 0x0002 + +#define PCI_VENDOR_ID_ENSONIQ 0x1274 +#define PCI_DEVICE_ID_ENSONIQ_AUDIOPCI 0x5000 +#define PCI_DEVICE_ID_ENSONIQ_ES1371 0x1371 + +#define PCI_VENDOR_ID_ALTEON 0x12ae +#define PCI_DEVICE_ID_ALTEON_ACENIC 0x0001 + +#define PCI_VENDOR_ID_PICTUREL 0x12c5 +#define PCI_DEVICE_ID_PICTUREL_PCIVST 0x0081 + +#define PCI_VENDOR_ID_NVIDIA_SGS 0x12d2 +#define PCI_DEVICE_ID_NVIDIA_SGS_RIVA128 0x0018 + +#define PCI_VENDOR_ID_CBOARDS 0x1307 +#define PCI_DEVICE_ID_CBOARDS_DAS1602_16 0x0001 + +#define PCI_VENDOR_ID_SIIG 0x131f +#define PCI_DEVICE_ID_SIIG_1S1P_10x_550 0x1010 +#define PCI_DEVICE_ID_SIIG_1S1P_10x_650 0x1011 +#define PCI_DEVICE_ID_SIIG_1S1P_10x_850 0x1012 +#define PCI_DEVICE_ID_SIIG_1P_10x 0x1020 +#define PCI_DEVICE_ID_SIIG_2P_10x 0x1021 +#define PCI_DEVICE_ID_SIIG_2S1P_10x_550 0x1034 +#define PCI_DEVICE_ID_SIIG_2S1P_10x_650 0x1035 +#define PCI_DEVICE_ID_SIIG_2S1P_10x_850 0x1036 +#define PCI_DEVICE_ID_SIIG_1P_20x 0x2020 +#define PCI_DEVICE_ID_SIIG_2P_20x 0x2021 +#define PCI_DEVICE_ID_SIIG_2P1S_20x_550 0x2040 +#define PCI_DEVICE_ID_SIIG_2P1S_20x_650 0x2041 +#define PCI_DEVICE_ID_SIIG_2P1S_20x_850 0x2042 +#define PCI_DEVICE_ID_SIIG_1S1P_20x_550 0x2010 +#define PCI_DEVICE_ID_SIIG_1S1P_20x_650 0x2011 +#define PCI_DEVICE_ID_SIIG_1S1P_20x_850 0x2012 +#define PCI_DEVICE_ID_SIIG_2S1P_20x_550 0x2060 +#define PCI_DEVICE_ID_SIIG_2S1P_20x_650 0x2061 +#define PCI_DEVICE_ID_SIIG_2S1P_20x_850 0x2062 + +#define PCI_VENDOR_ID_NETGEAR 0x1385 +#define PCI_DEVICE_ID_NETGEAR_GA620 0x620a + +#define PCI_VENDOR_ID_LAVA 0x1407 +#define PCI_DEVICE_ID_LAVA_PARALLEL 0x8000 +#define PCI_DEVICE_ID_LAVA_DUAL_PAR_A 0x8002 /* The Lava Dual Parallel is */ +#define PCI_DEVICE_ID_LAVA_DUAL_PAR_B 0x8003 /* two PCI devices on a card */ + +#define PCI_VENDOR_ID_TIMEDIA 0x1409 +#define PCI_DEVICE_ID_TIMEDIA_1889 0x7168 +#define PCI_DEVICE_ID_TIMEDIA_4008A 0x7268 + +#define PCI_VENDOR_ID_AFAVLAB 0x14db +#define PCI_DEVICE_ID_AFAVLAB_TK9902 0x2120 + +#define PCI_VENDOR_ID_SYMPHONY 0x1c1c +#define PCI_DEVICE_ID_SYMPHONY_101 0x0001 + +#define PCI_VENDOR_ID_TEKRAM 0x1de1 +#define PCI_DEVICE_ID_TEKRAM_DC290 0xdc29 + +#define PCI_VENDOR_ID_3DLABS 0x3d3d +#define PCI_DEVICE_ID_3DLABS_300SX 0x0001 +#define PCI_DEVICE_ID_3DLABS_500TX 0x0002 +#define PCI_DEVICE_ID_3DLABS_DELTA 0x0003 +#define PCI_DEVICE_ID_3DLABS_PERMEDIA 0x0004 +#define PCI_DEVICE_ID_3DLABS_MX 0x0006 +#define PCI_DEVICE_ID_3DLABS_PERMEDIA2 0x0007 +#define PCI_DEVICE_ID_3DLABS_GAMMA 0x0008 +#define PCI_DEVICE_ID_3DLABS_PERMEDIA2V 0x0009 + +#define PCI_VENDOR_ID_AVANCE 0x4005 +#define PCI_DEVICE_ID_AVANCE_ALG2064 0x2064 +#define PCI_DEVICE_ID_AVANCE_2302 0x2302 + +#define PCI_VENDOR_ID_NETVIN 0x4a14 +#define PCI_DEVICE_ID_NETVIN_NV5000SC 0x5000 + +#define PCI_VENDOR_ID_S3 0x5333 +#define PCI_DEVICE_ID_S3_PLATO_PXS 0x0551 +#define PCI_DEVICE_ID_S3_ViRGE 0x5631 +#define PCI_DEVICE_ID_S3_TRIO 0x8811 +#define PCI_DEVICE_ID_S3_AURORA64VP 0x8812 +#define PCI_DEVICE_ID_S3_TRIO64UVP 0x8814 +#define PCI_DEVICE_ID_S3_ViRGE_VX 0x883d +#define PCI_DEVICE_ID_S3_868 0x8880 +#define PCI_DEVICE_ID_S3_928 0x88b0 +#define PCI_DEVICE_ID_S3_864_1 0x88c0 +#define PCI_DEVICE_ID_S3_864_2 0x88c1 +#define PCI_DEVICE_ID_S3_964_1 0x88d0 +#define PCI_DEVICE_ID_S3_964_2 0x88d1 +#define PCI_DEVICE_ID_S3_968 0x88f0 +#define PCI_DEVICE_ID_S3_TRIO64V2 0x8901 +#define PCI_DEVICE_ID_S3_PLATO_PXG 0x8902 +#define PCI_DEVICE_ID_S3_ViRGE_DXGX 0x8a01 +#define PCI_DEVICE_ID_S3_ViRGE_GX2 0x8a10 +#define PCI_DEVICE_ID_S3_ViRGE_MX 0x8c01 +#define PCI_DEVICE_ID_S3_ViRGE_MXP 0x8c02 +#define PCI_DEVICE_ID_S3_ViRGE_MXPMV 0x8c03 +#define PCI_DEVICE_ID_S3_SONICVIBES 0xca00 + +#define PCI_VENDOR_ID_DCI 0x6666 +#define PCI_DEVICE_ID_DCI_PCCOM4 0x0001 + +#define PCI_VENDOR_ID_GENROCO 0x5555 +#define PCI_DEVICE_ID_GENROCO_HFP832 0x0003 + +#define PCI_VENDOR_ID_INTEL 0x8086 +#define PCI_DEVICE_ID_INTEL_21145 0x0039 +#define PCI_DEVICE_ID_INTEL_82375 0x0482 +#define PCI_DEVICE_ID_INTEL_82424 0x0483 +#define PCI_DEVICE_ID_INTEL_82378 0x0484 +#define PCI_DEVICE_ID_INTEL_82430 0x0486 +#define PCI_DEVICE_ID_INTEL_82434 0x04a3 +#define PCI_DEVICE_ID_INTEL_I960 0x0960 +#define PCI_DEVICE_ID_INTEL_I960RN 0x0964 +#define PCI_DEVICE_ID_INTEL_82559ER 0x1209 +#define PCI_DEVICE_ID_INTEL_82092AA_0 0x1221 +#define PCI_DEVICE_ID_INTEL_82092AA_1 0x1222 +#define PCI_DEVICE_ID_INTEL_7116 0x1223 +#define PCI_DEVICE_ID_INTEL_82596 0x1226 +#define PCI_DEVICE_ID_INTEL_82865 0x1227 +#define PCI_DEVICE_ID_INTEL_82557 0x1229 +#define PCI_DEVICE_ID_INTEL_82437 0x122d +#define PCI_DEVICE_ID_INTEL_82371FB_0 0x122e +#define PCI_DEVICE_ID_INTEL_82371FB_1 0x1230 +#define PCI_DEVICE_ID_INTEL_82371MX 0x1234 +#define PCI_DEVICE_ID_INTEL_82437MX 0x1235 +#define PCI_DEVICE_ID_INTEL_82441 0x1237 +#define PCI_DEVICE_ID_INTEL_82380FB 0x124b +#define PCI_DEVICE_ID_INTEL_82439 0x1250 +#define PCI_DEVICE_ID_INTEL_MEGARAID 0x1960 +#define PCI_DEVICE_ID_INTEL_82371SB_0 0x7000 +#define PCI_DEVICE_ID_INTEL_82371SB_1 0x7010 +#define PCI_DEVICE_ID_INTEL_82371SB_2 0x7020 +#define PCI_DEVICE_ID_INTEL_82437VX 0x7030 +#define PCI_DEVICE_ID_INTEL_82439TX 0x7100 +#define PCI_DEVICE_ID_INTEL_82371AB_0 0x7110 +#define PCI_DEVICE_ID_INTEL_82371AB 0x7111 +#define PCI_DEVICE_ID_INTEL_82371AB_2 0x7112 +#define PCI_DEVICE_ID_INTEL_82371AB_3 0x7113 +#define PCI_DEVICE_ID_INTEL_82443LX_0 0x7180 +#define PCI_DEVICE_ID_INTEL_82443LX_1 0x7181 +#define PCI_DEVICE_ID_INTEL_82443BX_0 0x7190 +#define PCI_DEVICE_ID_INTEL_82443BX_1 0x7191 +#define PCI_DEVICE_ID_INTEL_82443BX_2 0x7192 +#define PCI_DEVICE_ID_INTEL_P6 0x84c4 +#define PCI_DEVICE_ID_INTEL_82450GX 0x84c4 +#define PCI_DEVICE_ID_INTEL_82453GX 0x84c5 +#define PCI_DEVICE_ID_INTEL_82451NX 0x84ca +#define PCI_DEVICE_ID_INTEL_82454NX 0x84cb + +#define PCI_VENDOR_ID_COMPUTONE 0x8e0e +#define PCI_DEVICE_ID_COMPUTONE_IP2EX 0x0291 + +#define PCI_VENDOR_ID_KTI 0x8e2e +#define PCI_DEVICE_ID_KTI_ET32P2 0x3000 + +#define PCI_VENDOR_ID_ADAPTEC 0x9004 +#define PCI_DEVICE_ID_ADAPTEC_7810 0x1078 +#define PCI_DEVICE_ID_ADAPTEC_7821 0x2178 +#define PCI_DEVICE_ID_ADAPTEC_38602 0x3860 +#define PCI_DEVICE_ID_ADAPTEC_7850 0x5078 +#define PCI_DEVICE_ID_ADAPTEC_7855 0x5578 +#define PCI_DEVICE_ID_ADAPTEC_5800 0x5800 +#define PCI_DEVICE_ID_ADAPTEC_3860 0x6038 +#define PCI_DEVICE_ID_ADAPTEC_1480A 0x6075 +#define PCI_DEVICE_ID_ADAPTEC_7860 0x6078 +#define PCI_DEVICE_ID_ADAPTEC_7861 0x6178 +#define PCI_DEVICE_ID_ADAPTEC_7870 0x7078 +#define PCI_DEVICE_ID_ADAPTEC_7871 0x7178 +#define PCI_DEVICE_ID_ADAPTEC_7872 0x7278 +#define PCI_DEVICE_ID_ADAPTEC_7873 0x7378 +#define PCI_DEVICE_ID_ADAPTEC_7874 0x7478 +#define PCI_DEVICE_ID_ADAPTEC_7895 0x7895 +#define PCI_DEVICE_ID_ADAPTEC_7880 0x8078 +#define PCI_DEVICE_ID_ADAPTEC_7881 0x8178 +#define PCI_DEVICE_ID_ADAPTEC_7882 0x8278 +#define PCI_DEVICE_ID_ADAPTEC_7883 0x8378 +#define PCI_DEVICE_ID_ADAPTEC_7884 0x8478 +#define PCI_DEVICE_ID_ADAPTEC_7885 0x8578 +#define PCI_DEVICE_ID_ADAPTEC_7886 0x8678 +#define PCI_DEVICE_ID_ADAPTEC_7887 0x8778 +#define PCI_DEVICE_ID_ADAPTEC_7888 0x8878 +#define PCI_DEVICE_ID_ADAPTEC_1030 0x8b78 + +#define PCI_VENDOR_ID_ADAPTEC2 0x9005 +#define PCI_DEVICE_ID_ADAPTEC2_2940U2 0x0010 +#define PCI_DEVICE_ID_ADAPTEC2_2930U2 0x0011 +#define PCI_DEVICE_ID_ADAPTEC2_7890B 0x0013 +#define PCI_DEVICE_ID_ADAPTEC2_7890 0x001f +#define PCI_DEVICE_ID_ADAPTEC2_3940U2 0x0050 +#define PCI_DEVICE_ID_ADAPTEC2_3950U2D 0x0051 +#define PCI_DEVICE_ID_ADAPTEC2_7896 0x005f +#define PCI_DEVICE_ID_ADAPTEC2_7892A 0x0080 +#define PCI_DEVICE_ID_ADAPTEC2_7892B 0x0081 +#define PCI_DEVICE_ID_ADAPTEC2_7892D 0x0083 +#define PCI_DEVICE_ID_ADAPTEC2_7892P 0x008f +#define PCI_DEVICE_ID_ADAPTEC2_7899A 0x00c0 +#define PCI_DEVICE_ID_ADAPTEC2_7899B 0x00c1 +#define PCI_DEVICE_ID_ADAPTEC2_7899D 0x00c3 +#define PCI_DEVICE_ID_ADAPTEC2_7899P 0x00cf + +#define PCI_VENDOR_ID_ATRONICS 0x907f +#define PCI_DEVICE_ID_ATRONICS_2015 0x2015 + +#define PCI_VENDOR_ID_HOLTEK 0x9412 +#define PCI_DEVICE_ID_HOLTEK_6565 0x6565 + +#define PCI_VENDOR_ID_TIGERJET 0xe159 +#define PCI_DEVICE_ID_TIGERJET_300 0x0001 + +#define PCI_VENDOR_ID_ARK 0xedd8 +#define PCI_DEVICE_ID_ARK_STING 0xa091 +#define PCI_DEVICE_ID_ARK_STINGARK 0xa099 +#define PCI_DEVICE_ID_ARK_2000MT 0xa0a1 + +#define PCI_VENDOR_ID_INTERPHASE 0x107e +#define PCI_DEVICE_ID_INTERPHASE_5526 0x0004 +#define PCI_DEVICE_ID_INTERPHASE_55x6 0x0005 + +/* + * The PCI interface treats multi-function devices as independent + * devices. The slot/function address of each device is encoded + * in a single byte as follows: + * + * 7:3 = slot + * 2:0 = function + */ +#define PCI_DEVFN(slot,func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) +#define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) +#define PCI_FUNC(devfn) ((devfn) & 0x07) + +#endif /* USE_2_2_17_PCI_H */ + +static void +do_pci(void) +{ + struct list_data pcilist_data; + int devcnt, i; + unsigned int class; + unsigned short device, vendor; + unsigned char busno; + ulong *devlist, bus, devfn, prev, next; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char buf3[BUFSIZE]; + + if (!symbol_exists("pci_devices")) + error(FATAL, "no PCI devices found on this system.\n"); + + BZERO(&pcilist_data, sizeof(struct list_data)); + + if (VALID_MEMBER(pci_dev_global_list)) { + get_symbol_data("pci_devices", sizeof(void *), &pcilist_data.start); + pcilist_data.end = symbol_value("pci_devices"); + pcilist_data.list_head_offset = OFFSET(pci_dev_global_list); + readmem(symbol_value("pci_devices") + OFFSET(list_head_prev), + KVADDR, &prev, sizeof(void *), "list head prev", + FAULT_ON_ERROR); + /* + * Check if this system does not have any PCI devices. + */ + if ((pcilist_data.start == pcilist_data.end) && + (prev == pcilist_data.end)) + error(FATAL, "no PCI devices found on this system.\n"); + + } else if (VALID_MEMBER(pci_dev_next)) { + get_symbol_data("pci_devices", sizeof(void *), + &pcilist_data.start); + pcilist_data.member_offset = OFFSET(pci_dev_next); + /* + * Check if this system does not have any PCI devices. + */ + readmem(pcilist_data.start + pcilist_data.member_offset, + KVADDR, &next, sizeof(void *), "pci dev next", + FAULT_ON_ERROR); + if (!next) + error(FATAL, "no PCI devices found on this system.\n"); + } else + option_not_supported('p'); + + hq_open(); + devcnt = do_list(&pcilist_data); + devlist = (ulong *)GETBUF(devcnt * sizeof(ulong)); + devcnt = retrieve_list(devlist, devcnt); + hq_close(); + + fprintf(fp, "%s BU:SL.FN CLASS: VENDOR-DEVICE\n", + mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "PCI_DEV")); + + for (i = 0; i < devcnt; i++) { + + /* + * Get the pci bus number + */ + readmem(devlist[i] + OFFSET(pci_dev_bus), KVADDR, &bus, + sizeof(void *), "pci bus", FAULT_ON_ERROR); + readmem(bus + OFFSET(pci_bus_number), KVADDR, &busno, + sizeof(char), "pci bus number", FAULT_ON_ERROR); + readmem(devlist[i] + OFFSET(pci_dev_devfn), KVADDR, + &devfn, sizeof(ulong), "pci devfn", FAULT_ON_ERROR); + + fprintf(fp, "%lx %02x:%02lx.%lx ", devlist[i], + busno, PCI_SLOT(devfn), PCI_FUNC(devfn)); + + /* + * Now read in the class, device, and vendor. + */ + readmem(devlist[i] + OFFSET(pci_dev_class), KVADDR, + &class, sizeof(int), "pci class", FAULT_ON_ERROR); + readmem(devlist[i] + OFFSET(pci_dev_device), + KVADDR, &device, sizeof(short), "pci device", + FAULT_ON_ERROR); + readmem(devlist[i] + OFFSET(pci_dev_vendor),KVADDR, + &vendor, sizeof(short), "pci vendor", FAULT_ON_ERROR); + + fprintf(fp, "%s: %s %s", + pci_strclass(class, buf1), + pci_strvendor(vendor, buf2), + pci_strdev(vendor, device, buf3)); + + fprintf(fp, "\n"); + } + + FREEBUF(devlist); +} + + + +/* + * Taken from drivers/pci/oldproc.c, kernel ver 2.2.17 + */ +struct pci_dev_info { + unsigned short vendor; /* vendor id */ + unsigned short device; /* device id */ + + const char *name; /* device name */ +}; + + +#define DEVICE(vid,did,name) \ + {PCI_VENDOR_ID_##vid, PCI_DEVICE_ID_##did, (name)} + +/* + * Sorted in ascending order by vendor and device. + * Use binary search for lookup. If you add a device make sure + * it is sequential by both vendor and device id. + */ +struct pci_dev_info dev_info[] = { + DEVICE( COMPAQ, COMPAQ_1280, "QVision 1280/p"), + DEVICE( COMPAQ, COMPAQ_6010, "Hot Plug PCI Bridge"), + DEVICE( COMPAQ, COMPAQ_SMART2P, "Smart-2/P RAID Controller"), + DEVICE( COMPAQ, COMPAQ_NETEL100,"Netelligent 10/100"), + DEVICE( COMPAQ, COMPAQ_NETEL10, "Netelligent 10"), + DEVICE( COMPAQ, COMPAQ_NETFLEX3I,"NetFlex 3"), + DEVICE( COMPAQ, COMPAQ_NETEL100D,"Netelligent 10/100 Dual"), + DEVICE( COMPAQ, COMPAQ_NETEL100PI,"Netelligent 10/100 ProLiant"), + DEVICE( COMPAQ, COMPAQ_NETEL100I,"Netelligent 10/100 Integrated"), + DEVICE( COMPAQ, COMPAQ_THUNDER, "ThunderLAN"), + DEVICE( COMPAQ, COMPAQ_NETFLEX3B,"NetFlex 3 BNC"), + DEVICE( NCR, NCR_53C810, "53c810"), + DEVICE( NCR, NCR_53C820, "53c820"), + DEVICE( NCR, NCR_53C825, "53c825"), + DEVICE( NCR, NCR_53C815, "53c815"), + DEVICE( NCR, NCR_53C860, "53c860"), + DEVICE( NCR, NCR_53C896, "53c896"), + DEVICE( NCR, NCR_53C895, "53c895"), + DEVICE( NCR, NCR_53C885, "53c885"), + DEVICE( NCR, NCR_53C875, "53c875"), + DEVICE( NCR, NCR_53C875J, "53c875J"), + DEVICE( ATI, ATI_68800, "68800AX"), + DEVICE( ATI, ATI_215CT222, "215CT222"), + DEVICE( ATI, ATI_210888CX, "210888CX"), + DEVICE( ATI, ATI_215GB, "Mach64 GB"), + DEVICE( ATI, ATI_215GD, "Mach64 GD (Rage Pro)"), + DEVICE( ATI, ATI_215GI, "Mach64 GI (Rage Pro)"), + DEVICE( ATI, ATI_215GP, "Mach64 GP (Rage Pro)"), + DEVICE( ATI, ATI_215GQ, "Mach64 GQ (Rage Pro)"), + DEVICE( ATI, ATI_215GT, "Mach64 GT (Rage II)"), + DEVICE( ATI, ATI_215GTB, "Mach64 GT (Rage II)"), + DEVICE( ATI, ATI_210888GX, "210888GX"), + DEVICE( ATI, ATI_215LG, "Mach64 LG (Rage Pro)"), + DEVICE( ATI, ATI_264LT, "Mach64 LT"), + DEVICE( ATI, ATI_264VT, "Mach64 VT"), + DEVICE( VLSI, VLSI_82C592, "82C592-FC1"), + DEVICE( VLSI, VLSI_82C593, "82C593-FC1"), + DEVICE( VLSI, VLSI_82C594, "82C594-AFC2"), + DEVICE( VLSI, VLSI_82C597, "82C597-AFC2"), + DEVICE( VLSI, VLSI_82C541, "82C541 Lynx"), + DEVICE( VLSI, VLSI_82C543, "82C543 Lynx ISA"), + DEVICE( VLSI, VLSI_82C532, "82C532"), + DEVICE( VLSI, VLSI_82C534, "82C534"), + DEVICE( VLSI, VLSI_82C535, "82C535"), + DEVICE( VLSI, VLSI_82C147, "82C147"), + DEVICE( VLSI, VLSI_VAS96011, "VAS96011 (Golden Gate II)"), + DEVICE( ADL, ADL_2301, "2301"), + DEVICE( NS, NS_87415, "87415"), + DEVICE( NS, NS_87410, "87410"), + DEVICE( TSENG, TSENG_W32P_2, "ET4000W32P"), + DEVICE( TSENG, TSENG_W32P_b, "ET4000W32P rev B"), + DEVICE( TSENG, TSENG_W32P_c, "ET4000W32P rev C"), + DEVICE( TSENG, TSENG_W32P_d, "ET4000W32P rev D"), + DEVICE( TSENG, TSENG_ET6000, "ET6000"), + DEVICE( WEITEK, WEITEK_P9000, "P9000"), + DEVICE( WEITEK, WEITEK_P9100, "P9100"), + DEVICE( DEC, DEC_BRD, "DC21050"), + DEVICE( DEC, DEC_TULIP, "DC21040"), + DEVICE( DEC, DEC_TGA, "TGA"), + DEVICE( DEC, DEC_TULIP_FAST, "DC21140"), + DEVICE( DEC, DEC_TGA2, "TGA2"), + DEVICE( DEC, DEC_FDDI, "DEFPA"), + DEVICE( DEC, DEC_TULIP_PLUS, "DC21041"), + DEVICE( DEC, DEC_21142, "DC21142"), + DEVICE( DEC, DEC_21052, "DC21052"), + DEVICE( DEC, DEC_21150, "DC21150"), + DEVICE( DEC, DEC_21152, "DC21152"), + DEVICE( DEC, DEC_21153, "DC21153"), + DEVICE( DEC, DEC_21154, "DC21154"), + DEVICE( DEC, DEC_21285, "DC21285 Footbridge"), + DEVICE( DEC, DEC_21554, "DC21554 DrawBridge"), + DEVICE( CIRRUS, CIRRUS_7548, "GD 7548"), + DEVICE( CIRRUS, CIRRUS_5430, "GD 5430"), + DEVICE( CIRRUS, CIRRUS_5434_4, "GD 5434"), + DEVICE( CIRRUS, CIRRUS_5434_8, "GD 5434"), + DEVICE( CIRRUS, CIRRUS_5436, "GD 5436"), + DEVICE( CIRRUS, CIRRUS_5446, "GD 5446"), + DEVICE( CIRRUS, CIRRUS_5480, "GD 5480"), + DEVICE( CIRRUS, CIRRUS_5464, "GD 5464"), + DEVICE( CIRRUS, CIRRUS_5465, "GD 5465"), + DEVICE( CIRRUS, CIRRUS_6729, "CL 6729"), + DEVICE( CIRRUS, CIRRUS_6832, "PD 6832"), + DEVICE( CIRRUS, CIRRUS_7542, "CL 7542"), + DEVICE( CIRRUS, CIRRUS_7543, "CL 7543"), + DEVICE( CIRRUS, CIRRUS_7541, "CL 7541"), + DEVICE( IBM, IBM_FIRE_CORAL, "Fire Coral"), + DEVICE( IBM, IBM_TR, "Token Ring"), + DEVICE( IBM, IBM_82G2675, "82G2675"), + DEVICE( IBM, IBM_MCA, "MicroChannel"), + DEVICE( IBM, IBM_82351, "82351"), + DEVICE( IBM, IBM_PYTHON, "Python"), + DEVICE( IBM, IBM_SERVERAID, "ServeRAID"), + DEVICE( IBM, IBM_TR_WAKE, "Wake On LAN Token Ring"), + DEVICE( IBM, IBM_MPIC, "MPIC-2 Interrupt Controller"), + DEVICE( IBM, IBM_3780IDSP, "MWave DSP"), + DEVICE( IBM, IBM_MPIC_2, "MPIC-2 ASIC Interrupt Controller"), + DEVICE( WD, WD_7197, "WD 7197"), + DEVICE( AMD, AMD_LANCE, "79C970"), + DEVICE( AMD, AMD_SCSI, "53C974"), + DEVICE( TRIDENT, TRIDENT_9397, "Cyber9397"), + DEVICE( TRIDENT, TRIDENT_9420, "TG 9420"), + DEVICE( TRIDENT, TRIDENT_9440, "TG 9440"), + DEVICE( TRIDENT, TRIDENT_9660, "TG 9660 / Cyber9385"), + DEVICE( TRIDENT, TRIDENT_9750, "Image 975"), + DEVICE( AI, AI_M1435, "M1435"), + DEVICE( MATROX, MATROX_MGA_2, "Atlas PX2085"), + DEVICE( MATROX, MATROX_MIL, "Millennium"), + DEVICE( MATROX, MATROX_MYS, "Mystique"), + DEVICE( MATROX, MATROX_MIL_2, "Millennium II"), + DEVICE( MATROX, MATROX_MIL_2_AGP,"Millennium II AGP"), + DEVICE( MATROX, MATROX_G200_PCI,"Matrox G200 PCI"), + DEVICE( MATROX, MATROX_G200_AGP,"Matrox G200 AGP"), + DEVICE( MATROX, MATROX_MGA_IMP, "MGA Impression"), + DEVICE( MATROX, MATROX_G100_MM, "Matrox G100 multi monitor"), + DEVICE( MATROX, MATROX_G100_AGP,"Matrox G100 AGP"), + DEVICE( CT, CT_65545, "65545"), + DEVICE( CT, CT_65548, "65548"), + DEVICE( CT, CT_65550, "65550"), + DEVICE( CT, CT_65554, "65554"), + DEVICE( CT, CT_65555, "65555"), + DEVICE( MIRO, MIRO_36050, "ZR36050"), + DEVICE( NEC, NEC_PCX2, "PowerVR PCX2"), + DEVICE( FD, FD_36C70, "TMC-18C30"), + DEVICE( SI, SI_5591_AGP, "5591/5592 AGP"), + DEVICE( SI, SI_6202, "6202"), + DEVICE( SI, SI_503, "85C503"), + DEVICE( SI, SI_ACPI, "ACPI"), + DEVICE( SI, SI_5597_VGA, "5597/5598 VGA"), + DEVICE( SI, SI_6205, "6205"), + DEVICE( SI, SI_501, "85C501"), + DEVICE( SI, SI_496, "85C496"), + DEVICE( SI, SI_601, "85C601"), + DEVICE( SI, SI_5107, "5107"), + DEVICE( SI, SI_5511, "85C5511"), + DEVICE( SI, SI_5513, "85C5513"), + DEVICE( SI, SI_5571, "5571"), + DEVICE( SI, SI_5591, "5591/5592 Host"), + DEVICE( SI, SI_5597, "5597/5598 Host"), + DEVICE( SI, SI_7001, "7001 USB"), + DEVICE( HP, HP_J2585A, "J2585A"), + DEVICE( HP, HP_J2585B, "J2585B (Lassen)"), + DEVICE( PCTECH, PCTECH_RZ1000, "RZ1000 (buggy)"), + DEVICE( PCTECH, PCTECH_RZ1001, "RZ1001 (buggy?)"), + DEVICE( PCTECH, PCTECH_SAMURAI_0,"Samurai 0"), + DEVICE( PCTECH, PCTECH_SAMURAI_1,"Samurai 1"), + DEVICE( PCTECH, PCTECH_SAMURAI_IDE,"Samurai IDE"), + DEVICE( DPT, DPT, "SmartCache/Raid"), + DEVICE( OPTI, OPTI_92C178, "92C178"), + DEVICE( OPTI, OPTI_82C557, "82C557 Viper-M"), + DEVICE( OPTI, OPTI_82C558, "82C558 Viper-M ISA+IDE"), + DEVICE( OPTI, OPTI_82C621, "82C621"), + DEVICE( OPTI, OPTI_82C700, "82C700"), + DEVICE( OPTI, OPTI_82C701, "82C701 FireStar Plus"), + DEVICE( OPTI, OPTI_82C814, "82C814 Firebridge 1"), + DEVICE( OPTI, OPTI_82C822, "82C822"), + DEVICE( OPTI, OPTI_82C825, "82C825 Firebridge 2"), + DEVICE( SGS, SGS_2000, "STG 2000X"), + DEVICE( SGS, SGS_1764, "STG 1764X"), + DEVICE( BUSLOGIC, BUSLOGIC_MULTIMASTER_NC, "MultiMaster NC"), + DEVICE( BUSLOGIC, BUSLOGIC_MULTIMASTER, "MultiMaster"), + DEVICE( BUSLOGIC, BUSLOGIC_FLASHPOINT, "FlashPoint"), + DEVICE( TI, TI_TVP4010, "TVP4010 Permedia"), + DEVICE( TI, TI_TVP4020, "TVP4020 Permedia 2"), + DEVICE( TI, TI_PCI1130, "PCI1130"), + DEVICE( TI, TI_PCI1131, "PCI1131"), + DEVICE( TI, TI_PCI1250, "PCI1250"), + DEVICE( OAK, OAK_OTI107, "OTI107"), + DEVICE( WINBOND2, WINBOND2_89C940,"NE2000-PCI"), + DEVICE( MOTOROLA, MOTOROLA_MPC105,"MPC105 Eagle"), + DEVICE( MOTOROLA, MOTOROLA_MPC106,"MPC106 Grackle"), + DEVICE( MOTOROLA, MOTOROLA_RAVEN, "Raven"), + DEVICE( MOTOROLA, MOTOROLA_FALCON,"Falcon"), + DEVICE( MOTOROLA, MOTOROLA_CPX8216,"CPX8216"), + DEVICE( PROMISE, PROMISE_20246, "IDE UltraDMA/33"), + DEVICE( PROMISE, PROMISE_5300, "DC5030"), + DEVICE( N9, N9_I128, "Imagine 128"), + DEVICE( N9, N9_I128_2, "Imagine 128v2"), + DEVICE( N9, N9_I128_T2R, "Revolution 3D"), + DEVICE( UMC, UMC_UM8673F, "UM8673F"), + DEVICE( UMC, UMC_UM8891A, "UM8891A"), + DEVICE( UMC, UMC_UM8886BF, "UM8886BF"), + DEVICE( UMC, UMC_UM8886A, "UM8886A"), + DEVICE( UMC, UMC_UM8881F, "UM8881F"), + DEVICE( UMC, UMC_UM8886F, "UM8886F"), + DEVICE( UMC, UMC_UM9017F, "UM9017F"), + DEVICE( UMC, UMC_UM8886N, "UM8886N"), + DEVICE( UMC, UMC_UM8891N, "UM8891N"), + DEVICE( X, X_AGX016, "ITT AGX016"), + DEVICE( PICOP, PICOP_PT86C52X, "PT86C52x Vesuvius"), + DEVICE( PICOP, PICOP_PT80C524, "PT80C524 Nile"), + DEVICE( MYLEX, MYLEX_DAC960_P, "DAC960 P Series"), + DEVICE( MYLEX, MYLEX_DAC960_PD,"DAC960 PD Series"), + DEVICE( MYLEX, MYLEX_DAC960_PG,"DAC960 PG Series"), + DEVICE( MYLEX, MYLEX_DAC960_LP,"DAC960 LP Series"), + DEVICE( MYLEX, MYLEX_DAC960_BA,"DAC960 BA Series"), + DEVICE( APPLE, APPLE_BANDIT, "Bandit"), + DEVICE( APPLE, APPLE_GC, "Grand Central"), + DEVICE( APPLE, APPLE_HYDRA, "Hydra"), + DEVICE( NEXGEN, NEXGEN_82C501, "82C501"), + DEVICE( QLOGIC, QLOGIC_ISP1020, "ISP1020"), + DEVICE( QLOGIC, QLOGIC_ISP1022, "ISP1022"), + DEVICE( CYRIX, CYRIX_5510, "5510"), + DEVICE( CYRIX, CYRIX_PCI_MASTER,"PCI Master"), + DEVICE( CYRIX, CYRIX_5520, "5520"), + DEVICE( CYRIX, CYRIX_5530_LEGACY,"5530 Kahlua Legacy"), + DEVICE( CYRIX, CYRIX_5530_SMI, "5530 Kahlua SMI"), + DEVICE( CYRIX, CYRIX_5530_IDE, "5530 Kahlua IDE"), + DEVICE( CYRIX, CYRIX_5530_AUDIO,"5530 Kahlua Audio"), + DEVICE( CYRIX, CYRIX_5530_VIDEO,"5530 Kahlua Video"), + DEVICE( LEADTEK, LEADTEK_805, "S3 805"), + DEVICE( CONTAQ, CONTAQ_82C599, "82C599"), + DEVICE( CONTAQ, CONTAQ_82C693, "82C693"), + DEVICE( OLICOM, OLICOM_OC3136, "OC-3136/3137"), + DEVICE( OLICOM, OLICOM_OC2315, "OC-2315"), + DEVICE( OLICOM, OLICOM_OC2325, "OC-2325"), + DEVICE( OLICOM, OLICOM_OC2183, "OC-2183/2185"), + DEVICE( OLICOM, OLICOM_OC2326, "OC-2326"), + DEVICE( OLICOM, OLICOM_OC6151, "OC-6151/6152"), + DEVICE( SUN, SUN_EBUS, "PCI-EBus Bridge"), + DEVICE( SUN, SUN_HAPPYMEAL, "Happy Meal Ethernet"), + DEVICE( SUN, SUN_SIMBA, "Advanced PCI Bridge"), + DEVICE( SUN, SUN_PBM, "PCI Bus Module"), + DEVICE( SUN, SUN_SABRE, "Ultra IIi PCI"), + DEVICE( CMD, CMD_640, "640 (buggy)"), + DEVICE( CMD, CMD_643, "643"), + DEVICE( CMD, CMD_646, "646"), + DEVICE( CMD, CMD_670, "670"), + DEVICE( VISION, VISION_QD8500, "QD-8500"), + DEVICE( VISION, VISION_QD8580, "QD-8580"), + DEVICE( BROOKTREE, BROOKTREE_848, "Bt848"), + DEVICE( BROOKTREE, BROOKTREE_849A, "Bt849"), + DEVICE( BROOKTREE, BROOKTREE_878_1,"Bt878 2nd Contr. (?)"), + DEVICE( BROOKTREE, BROOKTREE_878, "Bt878"), + DEVICE( BROOKTREE, BROOKTREE_8474, "Bt8474"), + DEVICE( SIERRA, SIERRA_STB, "STB Horizon 64"), + DEVICE( ACC, ACC_2056, "2056"), + DEVICE( WINBOND, WINBOND_83769, "W83769F"), + DEVICE( WINBOND, WINBOND_82C105, "SL82C105"), + DEVICE( WINBOND, WINBOND_83C553, "W83C553"), + DEVICE( DATABOOK, DATABOOK_87144, "DB87144"), + DEVICE( PLX, PLX_9050, "PCI9050 I2O"), + DEVICE( PLX, PLX_9080, "PCI9080 I2O"), + DEVICE( MADGE, MADGE_MK2, "Smart 16/4 BM Mk2 Ringnode"), + DEVICE( MADGE, MADGE_C155S, "Collage 155 Server"), + DEVICE( 3COM, 3COM_3C339, "3C339 TokenRing"), + DEVICE( 3COM, 3COM_3C590, "3C590 10bT"), + DEVICE( 3COM, 3COM_3C595TX, "3C595 100bTX"), + DEVICE( 3COM, 3COM_3C595T4, "3C595 100bT4"), + DEVICE( 3COM, 3COM_3C595MII, "3C595 100b-MII"), + DEVICE( 3COM, 3COM_3C900TPO, "3C900 10bTPO"), + DEVICE( 3COM, 3COM_3C900COMBO,"3C900 10b Combo"), + DEVICE( 3COM, 3COM_3C905TX, "3C905 100bTX"), + DEVICE( 3COM, 3COM_3C905T4, "3C905 100bT4"), + DEVICE( 3COM, 3COM_3C905B_TX, "3C905B 100bTX"), + DEVICE( SMC, SMC_EPIC100, "9432 TX"), + DEVICE( AL, AL_M1445, "M1445"), + DEVICE( AL, AL_M1449, "M1449"), + DEVICE( AL, AL_M1451, "M1451"), + DEVICE( AL, AL_M1461, "M1461"), + DEVICE( AL, AL_M1489, "M1489"), + DEVICE( AL, AL_M1511, "M1511"), + DEVICE( AL, AL_M1513, "M1513"), + DEVICE( AL, AL_M1521, "M1521"), + DEVICE( AL, AL_M1523, "M1523"), + DEVICE( AL, AL_M1531, "M1531 Aladdin IV"), + DEVICE( AL, AL_M1533, "M1533 Aladdin IV"), + DEVICE( AL, AL_M3307, "M3307 MPEG-1 decoder"), + DEVICE( AL, AL_M4803, "M4803"), + DEVICE( AL, AL_M5219, "M5219"), + DEVICE( AL, AL_M5229, "M5229 TXpro"), + DEVICE( AL, AL_M5237, "M5237 USB"), + DEVICE( SURECOM, SURECOM_NE34, "NE-34PCI LAN"), + DEVICE( NEOMAGIC, NEOMAGIC_MAGICGRAPH_NM2070, "Magicgraph NM2070"), + DEVICE( NEOMAGIC, NEOMAGIC_MAGICGRAPH_128V, "MagicGraph 128V"), + DEVICE( NEOMAGIC, NEOMAGIC_MAGICGRAPH_128ZV, "MagicGraph 128ZV"), + DEVICE( NEOMAGIC, NEOMAGIC_MAGICGRAPH_NM2160, "MagicGraph NM2160"), + DEVICE( NEOMAGIC, NEOMAGIC_MAGICGRAPH_128ZVPLUS, "MagicGraph 128ZV+"), + DEVICE( ASP, ASP_ABP940, "ABP940"), + DEVICE( ASP, ASP_ABP940U, "ABP940U"), + DEVICE( ASP, ASP_ABP940UW, "ABP940UW"), + DEVICE( MACRONIX, MACRONIX_MX98713,"MX98713"), + DEVICE( MACRONIX, MACRONIX_MX987x5,"MX98715 / MX98725"), + DEVICE( CERN, CERN_SPSB_PMC, "STAR/RD24 SCI-PCI (PMC)"), + DEVICE( CERN, CERN_SPSB_PCI, "STAR/RD24 SCI-PCI (PMC)"), + DEVICE( CERN, CERN_HIPPI_DST, "HIPPI destination"), + DEVICE( CERN, CERN_HIPPI_SRC, "HIPPI source"), + DEVICE( IMS, IMS_8849, "8849"), + DEVICE( TEKRAM2, TEKRAM2_690c, "DC690c"), + DEVICE( TUNDRA, TUNDRA_CA91C042,"CA91C042 Universe"), + DEVICE( AMCC, AMCC_MYRINET, "Myrinet PCI (M2-PCI-32)"), + DEVICE( AMCC, AMCC_PARASTATION,"ParaStation Interface"), + DEVICE( AMCC, AMCC_S5933, "S5933 PCI44"), + DEVICE( AMCC, AMCC_S5933_HEPC3,"S5933 Traquair HEPC3"), + DEVICE( INTERG, INTERG_1680, "IGA-1680"), + DEVICE( INTERG, INTERG_1682, "IGA-1682"), + DEVICE( REALTEK, REALTEK_8029, "8029"), + DEVICE( REALTEK, REALTEK_8129, "8129"), + DEVICE( REALTEK, REALTEK_8139, "8139"), + DEVICE( TRUEVISION, TRUEVISION_T1000,"TARGA 1000"), + DEVICE( INIT, INIT_320P, "320 P"), + DEVICE( INIT, INIT_360P, "360 P"), + DEVICE( TTI, TTI_HPT343, "HPT343"), + DEVICE( VIA, VIA_82C505, "VT 82C505"), + DEVICE( VIA, VIA_82C561, "VT 82C561"), + DEVICE( VIA, VIA_82C586_1, "VT 82C586 Apollo IDE"), + DEVICE( VIA, VIA_82C576, "VT 82C576 3V"), + DEVICE( VIA, VIA_82C585, "VT 82C585 Apollo VP1/VPX"), + DEVICE( VIA, VIA_82C586_0, "VT 82C586 Apollo ISA"), + DEVICE( VIA, VIA_82C595, "VT 82C595 Apollo VP2"), + DEVICE( VIA, VIA_82C596_0, "VT 82C596 Apollo Pro"), + DEVICE( VIA, VIA_82C597_0, "VT 82C597 Apollo VP3"), + DEVICE( VIA, VIA_82C598_0, "VT 82C598 Apollo MVP3"), + DEVICE( VIA, VIA_82C926, "VT 82C926 Amazon"), + DEVICE( VIA, VIA_82C416, "VT 82C416MV"), + DEVICE( VIA, VIA_82C595_97, "VT 82C595 Apollo VP2/97"), + DEVICE( VIA, VIA_82C586_2, "VT 82C586 Apollo USB"), + DEVICE( VIA, VIA_82C586_3, "VT 82C586B Apollo ACPI"), + DEVICE( VIA, VIA_86C100A, "VT 86C100A"), + DEVICE( VIA, VIA_82C597_1, "VT 82C597 Apollo VP3 AGP"), + DEVICE( VIA, VIA_82C598_1, "VT 82C598 Apollo MVP3 AGP"), + DEVICE( SMC2, SMC2_1211TX, "1211 TX"), + DEVICE( VORTEX, VORTEX_GDT60x0, "GDT 60x0"), + DEVICE( VORTEX, VORTEX_GDT6000B,"GDT 6000b"), + DEVICE( VORTEX, VORTEX_GDT6x10, "GDT 6110/6510"), + DEVICE( VORTEX, VORTEX_GDT6x20, "GDT 6120/6520"), + DEVICE( VORTEX, VORTEX_GDT6530, "GDT 6530"), + DEVICE( VORTEX, VORTEX_GDT6550, "GDT 6550"), + DEVICE( VORTEX, VORTEX_GDT6x17, "GDT 6117/6517"), + DEVICE( VORTEX, VORTEX_GDT6x27, "GDT 6127/6527"), + DEVICE( VORTEX, VORTEX_GDT6537, "GDT 6537"), + DEVICE( VORTEX, VORTEX_GDT6557, "GDT 6557"), + DEVICE( VORTEX, VORTEX_GDT6x15, "GDT 6115/6515"), + DEVICE( VORTEX, VORTEX_GDT6x25, "GDT 6125/6525"), + DEVICE( VORTEX, VORTEX_GDT6535, "GDT 6535"), + DEVICE( VORTEX, VORTEX_GDT6555, "GDT 6555"), + DEVICE( VORTEX, VORTEX_GDT6x17RP,"GDT 6117RP/6517RP"), + DEVICE( VORTEX, VORTEX_GDT6x27RP,"GDT 6127RP/6527RP"), + DEVICE( VORTEX, VORTEX_GDT6537RP,"GDT 6537RP"), + DEVICE( VORTEX, VORTEX_GDT6557RP,"GDT 6557RP"), + DEVICE( VORTEX, VORTEX_GDT6x11RP,"GDT 6111RP/6511RP"), + DEVICE( VORTEX, VORTEX_GDT6x21RP,"GDT 6121RP/6521RP"), + DEVICE( VORTEX, VORTEX_GDT6x17RP1,"GDT 6117RP1/6517RP1"), + DEVICE( VORTEX, VORTEX_GDT6x27RP1,"GDT 6127RP1/6527RP1"), + DEVICE( VORTEX, VORTEX_GDT6537RP1,"GDT 6537RP1"), + DEVICE( VORTEX, VORTEX_GDT6557RP1,"GDT 6557RP1"), + DEVICE( VORTEX, VORTEX_GDT6x11RP1,"GDT 6111RP1/6511RP1"), + DEVICE( VORTEX, VORTEX_GDT6x21RP1,"GDT 6121RP1/6521RP1"), + DEVICE( VORTEX, VORTEX_GDT6x17RP2,"GDT 6117RP2/6517RP2"), + DEVICE( VORTEX, VORTEX_GDT6x27RP2,"GDT 6127RP2/6527RP2"), + DEVICE( VORTEX, VORTEX_GDT6537RP2,"GDT 6537RP2"), + DEVICE( VORTEX, VORTEX_GDT6557RP2,"GDT 6557RP2"), + DEVICE( VORTEX, VORTEX_GDT6x11RP2,"GDT 6111RP2/6511RP2"), + DEVICE( VORTEX, VORTEX_GDT6x21RP2,"GDT 6121RP2/6521RP2"), + DEVICE( EF, EF_ATM_FPGA, "155P-MF1 (FPGA)"), + DEVICE( EF, EF_ATM_ASIC, "155P-MF1 (ASIC)"), + DEVICE( FORE, FORE_PCA200PC, "PCA-200PC"), + DEVICE( FORE, FORE_PCA200E, "PCA-200E"), + DEVICE( IMAGINGTECH, IMAGINGTECH_ICPCI, "MVC IC-PCI"), + DEVICE( PHILIPS, PHILIPS_SAA7145,"SAA7145"), + DEVICE( PHILIPS, PHILIPS_SAA7146,"SAA7146"), + DEVICE( CYCLONE, CYCLONE_SDK, "SDK"), + DEVICE( ALLIANCE, ALLIANCE_PROMOTIO, "Promotion-6410"), + DEVICE( ALLIANCE, ALLIANCE_PROVIDEO, "Provideo"), + DEVICE( ALLIANCE, ALLIANCE_AT24, "AT24"), + DEVICE( ALLIANCE, ALLIANCE_AT3D, "AT3D"), + DEVICE( SYSKONNECT, SYSKONNECT_FP, "SK-FDDI-PCI"), + DEVICE( SYSKONNECT, SYSKONNECT_TR, "SK-TR-PCI"), + DEVICE( SYSKONNECT, SYSKONNECT_GE, "SK-98xx"), + DEVICE( VMIC, VMIC_VME, "VMIVME-7587"), + DEVICE( DIGI, DIGI_EPC, "AccelPort EPC"), + DEVICE( DIGI, DIGI_RIGHTSWITCH, "RightSwitch SE-6"), + DEVICE( DIGI, DIGI_XEM, "AccelPort Xem"), + DEVICE( DIGI, DIGI_XR, "AccelPort Xr"), + DEVICE( DIGI, DIGI_CX, "AccelPort C/X"), + DEVICE( DIGI, DIGI_XRJ, "AccelPort Xr/J"), + DEVICE( DIGI, DIGI_EPCJ, "AccelPort EPC/J"), + DEVICE( DIGI, DIGI_XR_920, "AccelPort Xr 920"), + DEVICE( MUTECH, MUTECH_MV1000, "MV-1000"), + DEVICE( RENDITION, RENDITION_VERITE,"Verite 1000"), + DEVICE( RENDITION, RENDITION_VERITE2100,"Verite 2100"), + DEVICE( SERVERWORKS, SERVERWORKS_HE, "CNB20HE PCI Bridge"), + DEVICE( SERVERWORKS, SERVERWORKS_LE, "CNB30LE PCI Bridge"), + DEVICE( SERVERWORKS, SERVERWORKS_CMIC_HE, "CMIC-HE PCI Bridge"), + DEVICE( SERVERWORKS, SERVERWORKS_CIOB30, "CIOB30 I/O Bridge"), + DEVICE( SERVERWORKS, SERVERWORKS_CSB5, "CSB5 PCI Bridge"), + DEVICE( TOSHIBA, TOSHIBA_601, "Laptop"), + DEVICE( TOSHIBA, TOSHIBA_TOPIC95,"ToPIC95"), + DEVICE( TOSHIBA, TOSHIBA_TOPIC97,"ToPIC97"), + DEVICE( RICOH, RICOH_RL5C466, "RL5C466"), + DEVICE( ARTOP, ARTOP_ATP8400, "ATP8400"), + DEVICE( ARTOP, ARTOP_ATP850UF, "ATP850UF"), + DEVICE( ZEITNET, ZEITNET_1221, "1221"), + DEVICE( ZEITNET, ZEITNET_1225, "1225"), + DEVICE( OMEGA, OMEGA_82C092G, "82C092G"), + DEVICE( LITEON, LITEON_LNE100TX,"LNE100TX"), + DEVICE( NP, NP_PCI_FDDI, "NP-PCI"), + DEVICE( ATT, ATT_L56XMF, "L56xMF"), + DEVICE( ATT, ATT_L56DVP, "L56DV+P"), + DEVICE( SPECIALIX, SPECIALIX_IO8, "IO8+/PCI"), + DEVICE( SPECIALIX, SPECIALIX_XIO, "XIO/SIO host"), + DEVICE( SPECIALIX, SPECIALIX_RIO, "RIO host"), + DEVICE( AURAVISION, AURAVISION_VXP524,"VXP524"), + DEVICE( IKON, IKON_10115, "10115 Greensheet"), + DEVICE( IKON, IKON_10117, "10117 Greensheet"), + DEVICE( ZORAN, ZORAN_36057, "ZR36057"), + DEVICE( ZORAN, ZORAN_36120, "ZR36120"), + DEVICE( KINETIC, KINETIC_2915, "2915 CAMAC"), + DEVICE( COMPEX, COMPEX_ENET100VG4, "Readylink ENET100-VG4"), + DEVICE( COMPEX, COMPEX_RL2000, "ReadyLink 2000"), + DEVICE( RP, RP32INTF, "RocketPort 32 Intf"), + DEVICE( RP, RP8INTF, "RocketPort 8 Intf"), + DEVICE( RP, RP16INTF, "RocketPort 16 Intf"), + DEVICE( RP, RP4QUAD, "Rocketport 4 Quad"), + DEVICE( RP, RP8OCTA, "RocketPort 8 Oct"), + DEVICE( RP, RP8J, "RocketPort 8 J"), + DEVICE( RP, RPP4, "RocketPort Plus 4 Quad"), + DEVICE( RP, RPP8, "RocketPort Plus 8 Oct"), + DEVICE( RP, RP8M, "RocketModem 8 J"), + DEVICE( CYCLADES, CYCLOM_Y_Lo, "Cyclom-Y below 1Mbyte"), + DEVICE( CYCLADES, CYCLOM_Y_Hi, "Cyclom-Y above 1Mbyte"), + DEVICE( CYCLADES, CYCLOM_4Y_Lo, "Cyclom-4Y below 1Mbyte"), + DEVICE( CYCLADES, CYCLOM_4Y_Hi, "Cyclom-4Y above 1Mbyte"), + DEVICE( CYCLADES, CYCLOM_8Y_Lo, "Cyclom-8Y below 1Mbyte"), + DEVICE( CYCLADES, CYCLOM_8Y_Hi, "Cyclom-8Y above 1Mbyte"), + DEVICE( CYCLADES, CYCLOM_Z_Lo, "Cyclades-Z below 1Mbyte"), + DEVICE( CYCLADES, CYCLOM_Z_Hi, "Cyclades-Z above 1Mbyte"), + DEVICE( CYCLADES, PC300_RX_2, "PC300/RSV or /X21 (2 ports)"), + DEVICE( CYCLADES, PC300_RX_1, "PC300/RSV or /X21 (1 port)"), + DEVICE( CYCLADES, PC300_TE_2, "PC300/TE (2 ports)"), + DEVICE( CYCLADES, PC300_TE_1, "PC300/TE (1 port)"), + DEVICE( ESSENTIAL, ESSENTIAL_ROADRUNNER,"Roadrunner serial HIPPI"), + DEVICE( O2, O2_6832, "6832"), + DEVICE( 3DFX, 3DFX_VOODOO, "Voodoo"), + DEVICE( 3DFX, 3DFX_VOODOO2, "Voodoo2"), + DEVICE( 3DFX, 3DFX_BANSHEE, "Banshee"), + DEVICE( SIGMADES, SIGMADES_6425, "REALmagic64/GX"), + DEVICE( AVM, AVM_A1, "A1 (Fritz)"), + DEVICE( STALLION, STALLION_ECHPCI832,"EasyConnection 8/32"), + DEVICE( STALLION, STALLION_ECHPCI864,"EasyConnection 8/64"), + DEVICE( STALLION, STALLION_EIOPCI,"EasyIO"), + DEVICE( OPTIBASE, OPTIBASE_FORGE, "MPEG Forge"), + DEVICE( OPTIBASE, OPTIBASE_FUSION,"MPEG Fusion"), + DEVICE( OPTIBASE, OPTIBASE_VPLEX, "VideoPlex"), + DEVICE( OPTIBASE, OPTIBASE_VPLEXCC,"VideoPlex CC"), + DEVICE( OPTIBASE, OPTIBASE_VQUEST,"VideoQuest"), + DEVICE( SATSAGEM, SATSAGEM_PCR2101,"PCR2101 DVB receiver"), + DEVICE( SATSAGEM, SATSAGEM_TELSATTURBO,"Telsat Turbo DVB"), + DEVICE( HUGHES, HUGHES_DIRECPC, "DirecPC"), + DEVICE( ENSONIQ, ENSONIQ_ES1371, "ES1371"), + DEVICE( ENSONIQ, ENSONIQ_AUDIOPCI,"AudioPCI"), + DEVICE( ALTEON, ALTEON_ACENIC, "AceNIC"), + DEVICE( PICTUREL, PICTUREL_PCIVST,"PCIVST"), + DEVICE( NVIDIA_SGS, NVIDIA_SGS_RIVA128, "Riva 128"), + DEVICE( CBOARDS, CBOARDS_DAS1602_16,"DAS1602/16"), + DEVICE( MOTOROLA_OOPS, MOTOROLA_FALCON,"Falcon"), + DEVICE( TIMEDIA, TIMEDIA_4008A, "Noname 4008A"), + DEVICE( SYMPHONY, SYMPHONY_101, "82C101"), + DEVICE( TEKRAM, TEKRAM_DC290, "DC-290"), + DEVICE( 3DLABS, 3DLABS_300SX, "GLINT 300SX"), + DEVICE( 3DLABS, 3DLABS_500TX, "GLINT 500TX"), + DEVICE( 3DLABS, 3DLABS_DELTA, "GLINT Delta"), + DEVICE( 3DLABS, 3DLABS_PERMEDIA,"PERMEDIA"), + DEVICE( 3DLABS, 3DLABS_MX, "GLINT MX"), + DEVICE( AVANCE, AVANCE_ALG2064, "ALG2064i"), + DEVICE( AVANCE, AVANCE_2302, "ALG-2302"), + DEVICE( NETVIN, NETVIN_NV5000SC,"NV5000"), + DEVICE( S3, S3_PLATO_PXS, "PLATO/PX (system)"), + DEVICE( S3, S3_ViRGE, "ViRGE"), + DEVICE( S3, S3_TRIO, "Trio32/Trio64"), + DEVICE( S3, S3_AURORA64VP, "Aurora64V+"), + DEVICE( S3, S3_TRIO64UVP, "Trio64UV+"), + DEVICE( S3, S3_ViRGE_VX, "ViRGE/VX"), + DEVICE( S3, S3_868, "Vision 868"), + DEVICE( S3, S3_928, "Vision 928-P"), + DEVICE( S3, S3_864_1, "Vision 864-P"), + DEVICE( S3, S3_864_2, "Vision 864-P"), + DEVICE( S3, S3_964_1, "Vision 964-P"), + DEVICE( S3, S3_964_2, "Vision 964-P"), + DEVICE( S3, S3_968, "Vision 968"), + DEVICE( S3, S3_TRIO64V2, "Trio64V2/DX or /GX"), + DEVICE( S3, S3_PLATO_PXG, "PLATO/PX (graphics)"), + DEVICE( S3, S3_ViRGE_DXGX, "ViRGE/DX or /GX"), + DEVICE( S3, S3_ViRGE_GX2, "ViRGE/GX2"), + DEVICE( S3, S3_ViRGE_MX, "ViRGE/MX"), + DEVICE( S3, S3_ViRGE_MXP, "ViRGE/MX+"), + DEVICE( S3, S3_ViRGE_MXPMV, "ViRGE/MX+MV"), + DEVICE( S3, S3_SONICVIBES, "SonicVibes"), + DEVICE( DCI, DCI_PCCOM4, "PC COM PCI Bus 4 port serial Adapter"), + DEVICE( GENROCO, GENROCO_HFP832, "TURBOstor HFP832"), + DEVICE( INTEL, INTEL_82375, "82375EB"), + DEVICE( INTEL, INTEL_82424, "82424ZX Saturn"), + DEVICE( INTEL, INTEL_82378, "82378IB"), + DEVICE( INTEL, INTEL_82430, "82430ZX Aries"), + DEVICE( INTEL, INTEL_82434, "82434LX Mercury/Neptune"), + DEVICE( INTEL, INTEL_I960, "i960"), + DEVICE( INTEL, INTEL_I960RN, "i960 RN"), + DEVICE( INTEL, INTEL_82559ER, "82559ER"), + DEVICE( INTEL, INTEL_82092AA_0,"82092AA PCMCIA bridge"), + DEVICE( INTEL, INTEL_82092AA_1,"82092AA EIDE"), + DEVICE( INTEL, INTEL_7116, "SAA7116"), + DEVICE( INTEL, INTEL_82596, "82596"), + DEVICE( INTEL, INTEL_82865, "82865"), + DEVICE( INTEL, INTEL_82557, "82557"), + DEVICE( INTEL, INTEL_82437, "82437"), + DEVICE( INTEL, INTEL_82371FB_0,"82371FB PIIX ISA"), + DEVICE( INTEL, INTEL_82371FB_1,"82371FB PIIX IDE"), + DEVICE( INTEL, INTEL_82371MX, "430MX - 82371MX MPIIX"), + DEVICE( INTEL, INTEL_82437MX, "430MX - 82437MX MTSC"), + DEVICE( INTEL, INTEL_82441, "82441FX Natoma"), + DEVICE( INTEL, INTEL_82380FB, "82380FB Mobile"), + DEVICE( INTEL, INTEL_82439, "82439HX Triton II"), + DEVICE( INTEL, INTEL_MEGARAID, "OEM MegaRAID Controller"), + DEVICE( INTEL, INTEL_82371SB_0,"82371SB PIIX3 ISA"), + DEVICE( INTEL, INTEL_82371SB_1,"82371SB PIIX3 IDE"), + DEVICE( INTEL, INTEL_82371SB_2,"82371SB PIIX3 USB"), + DEVICE( INTEL, INTEL_82437VX, "82437VX Triton II"), + DEVICE( INTEL, INTEL_82439TX, "82439TX"), + DEVICE( INTEL, INTEL_82371AB_0,"82371AB PIIX4 ISA"), + DEVICE( INTEL, INTEL_82371AB, "82371AB PIIX4 IDE"), + DEVICE( INTEL, INTEL_82371AB_2,"82371AB PIIX4 USB"), + DEVICE( INTEL, INTEL_82371AB_3,"82371AB PIIX4 ACPI"), + DEVICE( INTEL, INTEL_82443LX_0,"440LX - 82443LX PAC Host"), + DEVICE( INTEL, INTEL_82443LX_1,"440LX - 82443LX PAC AGP"), + DEVICE( INTEL, INTEL_82443BX_0,"440BX - 82443BX Host"), + DEVICE( INTEL, INTEL_82443BX_1,"440BX - 82443BX AGP"), + DEVICE( INTEL, INTEL_82443BX_2,"440BX - 82443BX Host (no AGP)"), + DEVICE( INTEL, INTEL_P6, "Orion P6"), + DEVICE( INTEL, INTEL_82450GX, "450KX/GX [Orion] - 82454KX/GX PCI Bridge"), + DEVICE( INTEL, INTEL_82453GX, "450KX/GX [Orion] - 82453KX/GX Memory Controller"), + DEVICE( INTEL, INTEL_82451NX, "450NX - 82451NX Memory & I/O Controller"), + DEVICE( INTEL, INTEL_82454NX, "450NX - 82454NX PCI Expander Bridge"), + DEVICE( COMPUTONE, COMPUTONE_IP2EX, "Computone IntelliPort Plus"), + DEVICE( KTI, KTI_ET32P2, "ET32P2"), + DEVICE( ADAPTEC, ADAPTEC_7810, "AIC-7810 RAID"), + DEVICE( ADAPTEC, ADAPTEC_7821, "AIC-7860"), + DEVICE( ADAPTEC, ADAPTEC_38602, "AIC-7860"), + DEVICE( ADAPTEC, ADAPTEC_7850, "AIC-7850"), + DEVICE( ADAPTEC, ADAPTEC_7855, "AIC-7855"), + DEVICE( ADAPTEC, ADAPTEC_5800, "AIC-5800"), + DEVICE( ADAPTEC, ADAPTEC_3860, "AIC-7860"), + DEVICE( ADAPTEC, ADAPTEC_7860, "AIC-7860"), + DEVICE( ADAPTEC, ADAPTEC_7861, "AIC-7861"), + DEVICE( ADAPTEC, ADAPTEC_7870, "AIC-7870"), + DEVICE( ADAPTEC, ADAPTEC_7871, "AIC-7871"), + DEVICE( ADAPTEC, ADAPTEC_7872, "AIC-7872"), + DEVICE( ADAPTEC, ADAPTEC_7873, "AIC-7873"), + DEVICE( ADAPTEC, ADAPTEC_7874, "AIC-7874"), + DEVICE( ADAPTEC, ADAPTEC_7895, "AIC-7895U"), + DEVICE( ADAPTEC, ADAPTEC_7880, "AIC-7880U"), + DEVICE( ADAPTEC, ADAPTEC_7881, "AIC-7881U"), + DEVICE( ADAPTEC, ADAPTEC_7882, "AIC-7882U"), + DEVICE( ADAPTEC, ADAPTEC_7883, "AIC-7883U"), + DEVICE( ADAPTEC, ADAPTEC_7884, "AIC-7884U"), + DEVICE( ADAPTEC, ADAPTEC_7885, "AIC-7885U"), + DEVICE( ADAPTEC, ADAPTEC_7886, "AIC-7886U"), + DEVICE( ADAPTEC, ADAPTEC_7887, "AIC-7887U"), + DEVICE( ADAPTEC, ADAPTEC_7888, "AIC-7888U"), + DEVICE( ADAPTEC, ADAPTEC_1030, "ABA-1030 DVB receiver"), + DEVICE( ADAPTEC2, ADAPTEC2_2940U2,"AHA-2940U2"), + DEVICE( ADAPTEC2, ADAPTEC2_2930U2,"AHA-2930U2"), + DEVICE( ADAPTEC2, ADAPTEC2_7890B, "AIC-7890/1"), + DEVICE( ADAPTEC2, ADAPTEC2_7890, "AIC-7890/1"), + DEVICE( ADAPTEC2, ADAPTEC2_3940U2,"AHA-3940U2"), + DEVICE( ADAPTEC2, ADAPTEC2_3950U2D,"AHA-3950U2D"), + DEVICE( ADAPTEC2, ADAPTEC2_7896, "AIC-7896/7"), + DEVICE( ADAPTEC2, ADAPTEC2_7892A, "AIC-7892"), + DEVICE( ADAPTEC2, ADAPTEC2_7892B, "AIC-7892"), + DEVICE( ADAPTEC2, ADAPTEC2_7892D, "AIC-7892"), + DEVICE( ADAPTEC2, ADAPTEC2_7892P, "AIC-7892"), + DEVICE( ADAPTEC2, ADAPTEC2_7899A, "AIC-7899"), + DEVICE( ADAPTEC2, ADAPTEC2_7899B, "AIC-7899"), + DEVICE( ADAPTEC2, ADAPTEC2_7899D, "AIC-7899"), + DEVICE( ADAPTEC2, ADAPTEC2_7899P, "AIC-7899"), + DEVICE( ATRONICS, ATRONICS_2015, "IDE-2015PL"), + DEVICE( TIGERJET, TIGERJET_300, "Tiger300 ISDN"), + DEVICE( ARK, ARK_STING, "Stingray"), + DEVICE( ARK, ARK_STINGARK, "Stingray ARK 2000PV"), + DEVICE( ARK, ARK_2000MT, "2000MT") +}; + + +/* + * device_info[] is sorted so we can use binary search + */ +static struct pci_dev_info * +pci_lookup_dev(unsigned int vendor, unsigned int dev) +{ + int min = 0, + max = sizeof(dev_info)/sizeof(dev_info[0]) - 1; + + for ( ; ; ) + { + int i = (min + max) >> 1; + long order; + + order = dev_info[i].vendor - (long) vendor; + if (!order) + order = dev_info[i].device - (long) dev; + + if (order < 0) + { + min = i + 1; + if ( min > max ) + return 0; + continue; + } + + if (order > 0) + { + max = i - 1; + if ( min > max ) + return 0; + continue; + } + + return & dev_info[ i ]; + } +} + + +static const char * +pci_strclass (unsigned int class, char *buf) +{ + char *s; + + switch (class >> 8) { + case PCI_CLASS_NOT_DEFINED: + s = "Non-VGA device"; + break; + case PCI_CLASS_NOT_DEFINED_VGA: + s = "VGA compatible device"; + break; + case PCI_CLASS_STORAGE_SCSI: + s = "SCSI storage controller"; + break; + case PCI_CLASS_STORAGE_IDE: + s = "IDE interface"; + break; + case PCI_CLASS_STORAGE_FLOPPY: + s = "Floppy disk controller"; + break; + case PCI_CLASS_STORAGE_IPI: + s = "IPI storage controller"; + break; + case PCI_CLASS_STORAGE_RAID: + s = "RAID storage controller"; + break; + case PCI_CLASS_STORAGE_OTHER: + s = "Unknown mass storage controller"; + break; + + case PCI_CLASS_NETWORK_ETHERNET: + s = "Ethernet controller"; + break; + case PCI_CLASS_NETWORK_TOKEN_RING: + s = "Token ring network controller"; + break; + case PCI_CLASS_NETWORK_FDDI: + s = "FDDI network controller"; + break; + case PCI_CLASS_NETWORK_ATM: + s = "ATM network controller"; + break; + case PCI_CLASS_NETWORK_OTHER: + s = "Network controller"; + break; + + case PCI_CLASS_DISPLAY_VGA: + s = "VGA compatible controller"; + break; + case PCI_CLASS_DISPLAY_XGA: + s = "XGA compatible controller"; + break; + case PCI_CLASS_DISPLAY_OTHER: + s = "Display controller"; + break; + + case PCI_CLASS_MULTIMEDIA_VIDEO: + s = "Multimedia video controller"; + break; + case PCI_CLASS_MULTIMEDIA_AUDIO: + s = "Multimedia audio controller"; + break; + case PCI_CLASS_MULTIMEDIA_OTHER: + s = "Multimedia controller"; + break; + + case PCI_CLASS_MEMORY_RAM: + s = "RAM memory"; + break; + case PCI_CLASS_MEMORY_FLASH: + s = "FLASH memory"; + break; + case PCI_CLASS_MEMORY_OTHER: + s = "Memory"; + break; + + case PCI_CLASS_BRIDGE_HOST: + s = "Host bridge"; + break; + case PCI_CLASS_BRIDGE_ISA: + s = "ISA bridge"; + break; + case PCI_CLASS_BRIDGE_EISA: + s = "EISA bridge"; + break; + case PCI_CLASS_BRIDGE_MC: + s = "MicroChannel bridge"; + break; + case PCI_CLASS_BRIDGE_PCI: + s = "PCI bridge"; + break; + case PCI_CLASS_BRIDGE_PCMCIA: + s = "PCMCIA bridge"; + break; + case PCI_CLASS_BRIDGE_NUBUS: + s = "NuBus bridge"; + break; + case PCI_CLASS_BRIDGE_CARDBUS: + s = "CardBus bridge"; + break; + case PCI_CLASS_BRIDGE_OTHER: + s = "Bridge"; + break; + + case PCI_CLASS_COMMUNICATION_SERIAL: + s = "Serial controller"; + break; + case PCI_CLASS_COMMUNICATION_PARALLEL: + s = "Parallel controller"; + break; + case PCI_CLASS_COMMUNICATION_OTHER: + s = "Communication controller"; + break; + + case PCI_CLASS_SYSTEM_PIC: + s = "PIC"; + break; + case PCI_CLASS_SYSTEM_DMA: + s = "DMA controller"; + break; + case PCI_CLASS_SYSTEM_TIMER: + s = "Timer"; + break; + case PCI_CLASS_SYSTEM_RTC: + s = "RTC"; + break; + case PCI_CLASS_SYSTEM_OTHER: + s = "System peripheral"; + break; + + case PCI_CLASS_INPUT_KEYBOARD: + s = "Keyboard controller"; + break; + case PCI_CLASS_INPUT_PEN: + s = "Digitizer Pen"; + break; + case PCI_CLASS_INPUT_MOUSE: + s = "Mouse controller"; + break; + case PCI_CLASS_INPUT_OTHER: + s = "Input device controller"; + break; + + case PCI_CLASS_DOCKING_GENERIC: + s = "Generic Docking Station"; + break; + case PCI_CLASS_DOCKING_OTHER: + s = "Docking Station"; + break; + + case PCI_CLASS_PROCESSOR_386: + s = "386"; + break; + case PCI_CLASS_PROCESSOR_486: + s = "486"; + break; + case PCI_CLASS_PROCESSOR_PENTIUM: + s = "Pentium"; + break; + case PCI_CLASS_PROCESSOR_ALPHA: + s = "Alpha"; + break; + case PCI_CLASS_PROCESSOR_POWERPC: + s = "Power PC"; + break; + case PCI_CLASS_PROCESSOR_CO: + s = "Co-processor"; + break; + + case PCI_CLASS_SERIAL_FIREWIRE: + s = "FireWire (IEEE 1394)"; + break; + case PCI_CLASS_SERIAL_ACCESS: + s = "ACCESS Bus"; + break; + case PCI_CLASS_SERIAL_SSA: + s = "SSA"; + break; + case PCI_CLASS_SERIAL_USB: + s = "USB Controller"; + break; + case PCI_CLASS_SERIAL_FIBER: + s = "Fiber Channel"; + break; + case PCI_CLASS_SERIAL_SMBUS: + s = "SM Bus"; + break; + + case PCI_CLASS_HOT_SWAP_CONTROLLER: + s = "Hot Swap Controller"; + break; + + default: + sprintf(buf, "[PCI_CLASS %x]", class); + s = buf; + break; + } + + return s; +} + + +static const char * +pci_strvendor(unsigned int vendor, char *buf) +{ + char *s; + + switch (vendor) { + case PCI_VENDOR_ID_COMPAQ: + s = "Compaq"; + break; + case PCI_VENDOR_ID_NCR: + s = "NCR"; + break; + case PCI_VENDOR_ID_ATI: + s = "ATI"; + break; + case PCI_VENDOR_ID_VLSI: + s = "VLSI"; + break; + case PCI_VENDOR_ID_ADL: + s = "Avance Logic"; + break; + case PCI_VENDOR_ID_NS: + s = "NS"; + break; + case PCI_VENDOR_ID_TSENG: + s = "Tseng'Lab"; + break; + case PCI_VENDOR_ID_WEITEK: + s = "Weitek"; + break; + case PCI_VENDOR_ID_DEC: + s = "DEC"; + break; + case PCI_VENDOR_ID_CIRRUS: + s = "Cirrus Logic"; + break; + case PCI_VENDOR_ID_IBM: + s = "IBM"; + break; + case PCI_VENDOR_ID_WD: + s = "Western Digital"; + break; + case PCI_VENDOR_ID_AMD: + s = "AMD"; + break; + case PCI_VENDOR_ID_TRIDENT: + s = "Trident"; + break; + case PCI_VENDOR_ID_AI: + s = "Acer Incorporated"; + break; + case PCI_VENDOR_ID_MATROX: + s = "Matrox"; + break; + case PCI_VENDOR_ID_CT: + s = "Chips & Technologies"; + break; + case PCI_VENDOR_ID_MIRO: + s = "Miro"; + break; + case PCI_VENDOR_ID_NEC: + s = "NEC"; + break; + case PCI_VENDOR_ID_FD: + s = "Future Domain"; + break; + case PCI_VENDOR_ID_SI: + s = "Silicon Integrated Systems"; + break; + case PCI_VENDOR_ID_HP: + s = "Hewlett Packard"; + break; + case PCI_VENDOR_ID_PCTECH: + s = "PCTECH"; + break; + case PCI_VENDOR_ID_DPT: + s = "DPT"; + break; + case PCI_VENDOR_ID_OPTI: + s = "OPTi"; + break; + case PCI_VENDOR_ID_SGS: + s = "SGS Thomson"; + break; + case PCI_VENDOR_ID_BUSLOGIC: + s = "BusLogic"; + break; + case PCI_VENDOR_ID_TI: + s = "Texas Instruments"; + break; + case PCI_VENDOR_ID_OAK: + s = "OAK"; + break; + case PCI_VENDOR_ID_WINBOND2: + s = "Winbond"; + break; + case PCI_VENDOR_ID_MOTOROLA: + s = "Motorola"; + break; + case PCI_VENDOR_ID_MOTOROLA_OOPS: + s = "Motorola"; + break; + case PCI_VENDOR_ID_PROMISE: + s = "Promise Technology"; + break; + case PCI_VENDOR_ID_N9: + s = "Number Nine"; + break; + case PCI_VENDOR_ID_UMC: + s = "UMC"; + break; + case PCI_VENDOR_ID_X: + s = "X TECHNOLOGY"; + break; + case PCI_VENDOR_ID_MYLEX: + s = "Mylex"; + break; + case PCI_VENDOR_ID_PICOP: + s = "PicoPower"; + break; + case PCI_VENDOR_ID_APPLE: + s = "Apple"; + break; + case PCI_VENDOR_ID_NEXGEN: + s = "Nexgen"; + break; + case PCI_VENDOR_ID_QLOGIC: + s = "Q Logic"; + break; + case PCI_VENDOR_ID_CYRIX: + s = "Cyrix"; + break; + case PCI_VENDOR_ID_LEADTEK: + s = "Leadtek Research"; + break; + case PCI_VENDOR_ID_CONTAQ: + s = "Contaq"; + break; + case PCI_VENDOR_ID_FOREX: + s = "Forex"; + break; + case PCI_VENDOR_ID_OLICOM: + s = "Olicom"; + break; + case PCI_VENDOR_ID_SUN: + s = "Sun Microsystems"; + break; + case PCI_VENDOR_ID_CMD: + s = "CMD"; + break; + case PCI_VENDOR_ID_VISION: + s = "Vision"; + break; + case PCI_VENDOR_ID_BROOKTREE: + s = "Brooktree"; + break; + case PCI_VENDOR_ID_SIERRA: + s = "Sierra"; + break; + case PCI_VENDOR_ID_ACC: + s = "ACC MICROELECTRONICS"; + break; + case PCI_VENDOR_ID_WINBOND: + s = "Winbond"; + break; + case PCI_VENDOR_ID_DATABOOK: + s = "Databook"; + break; + case PCI_VENDOR_ID_PLX: + s = "PLX"; + break; + case PCI_VENDOR_ID_MADGE: + s = "Madge Networks"; + break; + case PCI_VENDOR_ID_3COM: + s = "3Com"; + break; + case PCI_VENDOR_ID_SMC: + s = "SMC"; + break; + case PCI_VENDOR_ID_AL: + s = "Acer Labs"; + break; + case PCI_VENDOR_ID_MITSUBISHI: + s = "Mitsubishi"; + break; + case PCI_VENDOR_ID_SURECOM: + s = "Surecom"; + break; + case PCI_VENDOR_ID_NEOMAGIC: + s = "Neomagic"; + break; + case PCI_VENDOR_ID_ASP: + s = "Advanced System Products"; + break; + case PCI_VENDOR_ID_MACRONIX: + s = "Macronix"; + break; + case PCI_VENDOR_ID_CERN: + s = "CERN"; + break; + case PCI_VENDOR_ID_NVIDIA: + s = "NVidia"; + break; + case PCI_VENDOR_ID_IMS: + s = "IMS"; + break; + case PCI_VENDOR_ID_TEKRAM2: + s = "Tekram"; + break; + case PCI_VENDOR_ID_TUNDRA: + s = "Tundra"; + break; + case PCI_VENDOR_ID_AMCC: + s = "AMCC"; + break; + case PCI_VENDOR_ID_INTERG: + s = "Intergraphics"; + break; + case PCI_VENDOR_ID_REALTEK: + s = "Realtek"; + break; + case PCI_VENDOR_ID_TRUEVISION: + s = "Truevision"; + break; + case PCI_VENDOR_ID_INIT: + s = "Initio Corp"; + break; + case PCI_VENDOR_ID_TTI: + s = "Triones Technologies, Inc."; + break; + case PCI_VENDOR_ID_VIA: + s = "VIA Technologies"; + break; + case PCI_VENDOR_ID_SMC2: + s = "SMC"; + break; + case PCI_VENDOR_ID_VORTEX: + s = "VORTEX"; + break; + case PCI_VENDOR_ID_EF: + s = "Efficient Networks"; + break; + case PCI_VENDOR_ID_FORE: + s = "Fore Systems"; + break; + case PCI_VENDOR_ID_IMAGINGTECH: + s = "Imaging Technology"; + break; + case PCI_VENDOR_ID_PHILIPS: + s = "Philips"; + break; + case PCI_VENDOR_ID_CYCLONE: + s = "Cyclone"; + break; + case PCI_VENDOR_ID_ALLIANCE: + s = "Alliance"; + break; + case PCI_VENDOR_ID_VMIC: + s = "VMIC"; + break; + case PCI_VENDOR_ID_DIGI: + s = "Digi Intl."; + break; + case PCI_VENDOR_ID_MUTECH: + s = "Mutech"; + break; + case PCI_VENDOR_ID_RENDITION: + s = "Rendition"; + break; + case PCI_VENDOR_ID_TOSHIBA: + s = "Toshiba"; + break; + case PCI_VENDOR_ID_RICOH: + s = "Ricoh"; + break; + case PCI_VENDOR_ID_ARTOP: + s = "Artop Electronics"; + break; + case PCI_VENDOR_ID_ZEITNET: + s = "ZeitNet"; + break; + case PCI_VENDOR_ID_OMEGA: + s = "Omega Micro"; + break; + case PCI_VENDOR_ID_LITEON: + s = "LiteOn"; + break; + case PCI_VENDOR_ID_NP: + s = "Network Peripherals"; + break; + case PCI_VENDOR_ID_ATT: + s = "Lucent (ex-AT&T) Microelectronics"; + break; + case PCI_VENDOR_ID_SPECIALIX: + s = "Specialix"; + break; + case PCI_VENDOR_ID_AURAVISION: + s = "Auravision"; + break; + case PCI_VENDOR_ID_IKON: + s = "Ikon"; + break; + case PCI_VENDOR_ID_ZORAN: + s = "Zoran"; + break; + case PCI_VENDOR_ID_KINETIC: + s = "Kinetic"; + break; + case PCI_VENDOR_ID_COMPEX: + s = "Compex"; + break; + case PCI_VENDOR_ID_RP: + s = "Comtrol"; + break; + case PCI_VENDOR_ID_CYCLADES: + s = "Cyclades"; + break; + case PCI_VENDOR_ID_ESSENTIAL: + s = "Essential Communications"; + break; + case PCI_VENDOR_ID_O2: + s = "O2 Micro"; + break; + case PCI_VENDOR_ID_3DFX: + s = "3Dfx"; + break; + case PCI_VENDOR_ID_SIGMADES: + s = "Sigma Designs"; + break; + case PCI_VENDOR_ID_AVM: + s = "AVM"; + break; + case PCI_VENDOR_ID_CCUBE: + s = "C-Cube"; + break; + case PCI_VENDOR_ID_DIPIX: + s = "Dipix"; + break; + case PCI_VENDOR_ID_STALLION: + s = "Stallion Technologies"; + break; + case PCI_VENDOR_ID_OPTIBASE: + s = "Optibase"; + break; + case PCI_VENDOR_ID_SATSAGEM: + s = "SatSagem"; + break; + case PCI_VENDOR_ID_HUGHES: + s = "Hughes"; + break; + case PCI_VENDOR_ID_ENSONIQ: + s = "Ensoniq"; + break; + case PCI_VENDOR_ID_ALTEON: + s = "Alteon"; + break; + case PCI_VENDOR_ID_PICTUREL: + s = "Picture Elements"; + break; + case PCI_VENDOR_ID_NVIDIA_SGS: + s = "NVidia/SGS Thomson"; + break; + case PCI_VENDOR_ID_CBOARDS: + s = "ComputerBoards"; + break; + case PCI_VENDOR_ID_TIMEDIA: + s = "Timedia Technology"; + break; + case PCI_VENDOR_ID_SYMPHONY: + s = "Symphony"; + break; + case PCI_VENDOR_ID_COMPUTONE: + s = "Computone Corporation"; + break; + case PCI_VENDOR_ID_TEKRAM: + s = "Tekram"; + break; + case PCI_VENDOR_ID_3DLABS: + s = "3Dlabs"; + break; + case PCI_VENDOR_ID_AVANCE: + s = "Avance"; + break; + case PCI_VENDOR_ID_NETVIN: + s = "NetVin"; + break; + case PCI_VENDOR_ID_S3: + s = "S3 Inc."; + break; + case PCI_VENDOR_ID_DCI: + s = "Decision Computer Int."; + break; + case PCI_VENDOR_ID_GENROCO: + s = "Genroco"; + break; + case PCI_VENDOR_ID_INTEL: + s = "Intel"; + break; + case PCI_VENDOR_ID_KTI: + s = "KTI"; + break; + case PCI_VENDOR_ID_ADAPTEC: + s = "Adaptec"; + break; + case PCI_VENDOR_ID_ADAPTEC2: + s = "Adaptec"; + break; + case PCI_VENDOR_ID_ATRONICS: + s = "Atronics"; + break; + case PCI_VENDOR_ID_TIGERJET: + s = "TigerJet"; + break; + case PCI_VENDOR_ID_ARK: + s = "ARK Logic"; + break; + case PCI_VENDOR_ID_SYSKONNECT: + s = "SysKonnect"; + break; + + default: + sprintf(buf, "[PCI_VENDOR %x]", vendor); + s = buf; + break; + } + + return s; +} + + +static const char * +pci_strdev(unsigned int vendor, unsigned int device, char *buf) +{ + struct pci_dev_info *info; + + if ((info = pci_lookup_dev(vendor, device))) + return info->name; + else { + sprintf(buf, "[PCI_DEVICE %x]", device); + return buf; + } +} + +/* + * If the disk's name is started with these strings, we will skip it and do not + * display its statistics. + */ +static char *skipped_disk_name[] = { + "ram", + "loop", + NULL +}; + +static int +is_skipped_disk(char *name) +{ + char **p = skipped_disk_name; + + while (*p) { + if (strncmp(name, *p, strlen(*p)) == 0) + return TRUE; + p++; + } + + return FALSE; +} + +struct diskio { + int read; + int write; +}; + +struct iter { + /* If the kernel uses klist, the address should be klist.k_list */ + long head_address; + long current_address; + long type_address; /* the address of symbol "disk_type" */ + + /* + * If it is true, it means request_list.count[2] contains async/sync + * requests. + */ + int sync_count; + int diskname_len; + + unsigned long (*next_disk)(struct iter *); + + /* + * The argument is the address of request_queue, and the function + * returns the total requests in the driver(not ended) + */ + unsigned int (*get_in_flight)(unsigned long); + + /* + * this function reads request_list.count[2], and the first argument + * is the address of request_queue. + */ + void (*get_diskio)(unsigned long , struct diskio *); + + /* + * check if device.type == &disk_type + * + * old kernel(version <= 2.6.24) does not have the symbol "disk_type", + * and this callback should be null. + */ + int (*match)(struct iter *, unsigned long); + + /* + * If the kernel uses list, the argument is the address of list_head, + * otherwise, the argument is the address of klist_node. + */ + unsigned long (*get_gendisk)(unsigned long); +}; + +/* kernel version <= 2.6.24 */ +static unsigned long +get_gendisk_1(unsigned long entry) +{ + return entry - OFFSET(kobject_entry) - OFFSET(gendisk_kobj); +} + +/* 2.6.24 < kernel version <= 2.6.27 */ +static unsigned long +get_gendisk_2(unsigned long entry) +{ + return entry - OFFSET(device_node) - OFFSET(gendisk_dev); +} + +/* kernel version > 2.6.27 && struct gendisk contains dev/__dev */ +static unsigned long +get_gendisk_3(unsigned long entry) +{ + return entry - OFFSET(device_knode_class) - OFFSET(gendisk_dev); +} + +/* kernel version > 2.6.27 && struct gendisk does not contain dev/__dev */ +static unsigned long +get_gendisk_4(unsigned long entry) +{ + return entry - OFFSET(device_knode_class) - OFFSET(hd_struct_dev) - + OFFSET(gendisk_part0); +} + +/* 2.6.24 < kernel version <= 2.6.27 */ +static int +match_list(struct iter *i, unsigned long entry) +{ + unsigned long device_address; + unsigned long device_type; + + device_address = entry - OFFSET(device_node); + readmem(device_address + OFFSET(device_type), KVADDR, &device_type, + sizeof(device_type), "device.type", FAULT_ON_ERROR); + if (device_type != i->type_address) + return FALSE; + + return TRUE; +} + +/* kernel version > 2.6.27 */ +static int +match_klist(struct iter *i, unsigned long entry) +{ + unsigned long device_address; + unsigned long device_type; + + device_address = entry - OFFSET(device_knode_class); + readmem(device_address + OFFSET(device_type), KVADDR, &device_type, + sizeof(device_type), "device.type", FAULT_ON_ERROR); + if (device_type != i->type_address) + return FALSE; + + return TRUE; +} + +/* old kernel(version <= 2.6.27): list */ +static unsigned long +next_disk_list(struct iter *i) +{ + unsigned long list_head_address, next_address; + + if (i->current_address) { + list_head_address = i->current_address; + } else { + list_head_address = i->head_address; + } + +again: + /* read list_head.next */ + readmem(list_head_address + OFFSET(list_head_next), KVADDR, + &next_address, sizeof(next_address), "list_head.next", + FAULT_ON_ERROR); + + if (next_address == i->head_address) + return 0; + + if (i->match && !i->match(i, next_address)) { + list_head_address = next_address; + goto again; + } + + i->current_address = next_address; + return i->get_gendisk(next_address); +} + +/* new kernel(version > 2.6.27): klist */ +static unsigned long +next_disk_klist(struct iter* i) +{ + unsigned long klist_node_address, list_head_address, next_address; + unsigned long n_klist; + + if (i->current_address) { + list_head_address = i->current_address; + } else { + list_head_address = i->head_address; + } + +again: + /* read list_head.next */ + readmem(list_head_address + OFFSET(list_head_next), KVADDR, + &next_address, sizeof(next_address), "list_head.next", + FAULT_ON_ERROR); + + /* skip dead klist_node */ + while(next_address != i->head_address) { + klist_node_address = next_address - OFFSET(klist_node_n_node); + readmem(klist_node_address + OFFSET(klist_node_n_klist), KVADDR, + &n_klist, sizeof(n_klist), "klist_node.n_klist", + FAULT_ON_ERROR); + if (!(n_klist & 1)) + break; + + /* the klist_node is dead, skip to next klist_node */ + readmem(next_address + OFFSET(list_head_next), KVADDR, + &next_address, sizeof(next_address), "list_head.next", + FAULT_ON_ERROR); + } + + if (next_address == i->head_address) + return 0; + + if (i->match && !i->match(i, klist_node_address)) { + list_head_address = next_address; + goto again; + } + + i->current_address = next_address; + return i->get_gendisk(klist_node_address); +} + +/* read request_queue.rq.count[2] */ +static void +get_diskio_1(unsigned long rq, struct diskio *io) +{ + int count[2]; + + readmem(rq + OFFSET(request_queue_rq) + OFFSET(request_list_count), + KVADDR, count, sizeof(int) * 2, "request_list.count", + FAULT_ON_ERROR); + + io->read = count[0]; + io->write = count[1]; +} + +/* request_queue.in_flight contains total requests */ +static unsigned int +get_in_flight_1(unsigned long rq) +{ + unsigned int in_flight; + + readmem(rq+ OFFSET(request_queue_in_flight), KVADDR, &in_flight, + sizeof(uint), "request_queue.in_flight", FAULT_ON_ERROR); + return in_flight; +} + +/* request_queue.in_flight[2] contains read/write requests */ +static unsigned int +get_in_flight_2(unsigned long rq) +{ + unsigned int in_flight[2]; + + readmem(rq+ OFFSET(request_queue_in_flight), KVADDR, in_flight, + sizeof(uint) * 2, "request_queue.in_flight", FAULT_ON_ERROR); + return in_flight[0] + in_flight[1]; +} + +static void +init_iter(struct iter *i) +{ + ARRAY_LENGTH_INIT(i->diskname_len, gendisk.disk_name, + "gendisk.disk_name", NULL, sizeof(char)); + if (i->diskname_len < 0 || i->diskname_len > BUFSIZE) { + option_not_supported('d'); + return; + } + + i->current_address = 0; + + /* check whether BLK_RW_SYNC exists */ + i->sync_count = + get_symbol_type("BLK_RW_SYNC", NULL, NULL) == TYPE_CODE_ENUM; + + if (SIZE(rq_in_flight) == sizeof(int)) { + i->get_in_flight = get_in_flight_1; + } else if (SIZE(rq_in_flight) == sizeof(int) * 2) { + i->get_in_flight = get_in_flight_2; + } else { + option_not_supported('d'); + return; + } + i->get_diskio = get_diskio_1; + + if (symbol_exists("block_subsys") || symbol_exists("block_kset")) { + /* kernel version <= 2.6.24 */ + unsigned long block_subsys_addr; + + if (symbol_exists("block_subsys")) + block_subsys_addr = symbol_value("block_subsys"); + else + block_subsys_addr = symbol_value("block_kset"); + if (VALID_STRUCT(subsystem)) + i->head_address = block_subsys_addr + + OFFSET(subsystem_kset) + OFFSET(kset_list); + else + i->head_address = block_subsys_addr + OFFSET(kset_list); + i->type_address = 0; + i->next_disk = next_disk_list; + i->match = NULL; + i->get_gendisk = get_gendisk_1; + } else if (symbol_exists("block_class")) { + unsigned long block_class_addr = symbol_value("block_class"); + + i->type_address = symbol_value("disk_type"); + if (VALID_MEMBER(class_devices) || + (VALID_MEMBER(class_private_devices) && + SIZE(class_private_devices) == SIZE(list_head))) { + /* 2.6.24 < kernel version <= 2.6.27, list */ + if (!VALID_STRUCT(class_private)) { + /* 2.6.24 < kernel version <= 2.6.26 */ + i->head_address = block_class_addr + + OFFSET(class_devices); + } else { + /* kernel version is 2.6.27 */ + unsigned long class_private_addr; + + readmem(block_class_addr + OFFSET(class_p), + KVADDR, &class_private_addr, + sizeof(class_private_addr), "class.p", + FAULT_ON_ERROR); + i->head_address = class_private_addr + + OFFSET(class_private_devices); + } + i->next_disk = next_disk_list; + i->match = match_list; + i->get_gendisk = get_gendisk_2; + } else { + /* kernel version > 2.6.27, klist */ + unsigned long class_private_addr; + readmem(block_class_addr + OFFSET(class_p), KVADDR, + &class_private_addr, sizeof(class_private_addr), + "class.p", FAULT_ON_ERROR); + + if (VALID_STRUCT(class_private)) { + /* 2.6.27 < kernel version <= 2.6.37-rc2 */ + i->head_address = class_private_addr + + OFFSET(class_private_devices); + } else { + /* kernel version > 2.6.37-rc2 */ + i->head_address = class_private_addr + + OFFSET(subsys_private_klist_devices); + } + i->head_address += OFFSET(klist_k_list); + i->next_disk = next_disk_klist; + i->match = match_klist; + if (VALID_MEMBER(gendisk_dev)) + i->get_gendisk = get_gendisk_3; + else + i->get_gendisk = get_gendisk_4; + } + } else { + option_not_supported('d'); + return; + } +} + +static void +display_one_diskio(struct iter *i, unsigned long gendisk) +{ + char disk_name[BUFSIZE + 1]; + char buf0[BUFSIZE]; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char buf3[BUFSIZE]; + char buf4[BUFSIZE]; + char buf5[BUFSIZE]; + int major; + unsigned long queue_addr; + unsigned int in_flight; + struct diskio io; + + memset(disk_name, 0, BUFSIZE + 1); + readmem(gendisk + OFFSET(gendisk_disk_name), KVADDR, disk_name, + i->diskname_len, "gen_disk.disk_name", FAULT_ON_ERROR); + if (is_skipped_disk(disk_name)) + return; + + readmem(gendisk + OFFSET(gendisk_queue), KVADDR, &queue_addr, + sizeof(ulong), "gen_disk.queue", FAULT_ON_ERROR); + readmem(gendisk + OFFSET(gendisk_major), KVADDR, &major, sizeof(int), + "gen_disk.major", FAULT_ON_ERROR); + i->get_diskio(queue_addr, &io); + in_flight = i->get_in_flight(queue_addr); + + fprintf(fp, "%s%s%s %s%s%s%s %s%5d%s%s%s%s%s%5u\n", + mkstring(buf0, 5, RJUST|INT_DEC, (char *)(unsigned long)major), + space(MINSPACE), + mkstring(buf1, VADDR_PRLEN, LJUST|LONG_HEX, (char *)gendisk), + space(MINSPACE), + mkstring(buf2, 10, LJUST, disk_name), + space(MINSPACE), + mkstring(buf3, VADDR_PRLEN <= 11 ? 11 : VADDR_PRLEN, + LJUST|LONG_HEX, (char *)queue_addr), + space(MINSPACE), + io.read + io.write, + space(MINSPACE), + mkstring(buf4, 5, RJUST|INT_DEC, + (char *)(unsigned long)io.read), + space(MINSPACE), + mkstring(buf5, 5, RJUST|INT_DEC, + (char *)(unsigned long)io.write), + space(MINSPACE), + in_flight); +} + +static void +display_all_diskio(void) +{ + struct iter i; + unsigned long gendisk; + char buf0[BUFSIZE]; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char buf3[BUFSIZE]; + char buf4[BUFSIZE]; + char buf5[BUFSIZE]; + + init_iter(&i); + + fprintf(fp, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", + "MAJOR", + space(MINSPACE), + mkstring(buf0, VADDR_PRLEN + 2, LJUST, "GENDISK"), + space(MINSPACE), + "NAME ", + space(MINSPACE), + mkstring(buf1, VADDR_PRLEN <= 11 ? 13 : VADDR_PRLEN + 2, LJUST, + "REQUEST_QUEUE"), + space(MINSPACE), + mkstring(buf2, 5, RJUST, "TOTAL"), + space(MINSPACE), + i.sync_count ? mkstring(buf3, 5, RJUST, "ASYNC") : + mkstring(buf3, 5, RJUST, "READ"), + space(MINSPACE), + i.sync_count ? mkstring(buf4, 5, RJUST, "SYNC") : + mkstring(buf4, 5, RJUST, "WRITE"), + space(MINSPACE), + mkstring(buf5, 5, RJUST, "DRV")); + + while ((gendisk = i.next_disk(&i)) != 0) + display_one_diskio(&i, gendisk); +} + +static +void diskio_init(void) +{ + if (dt->flags & DISKIO_INIT) + return; + + MEMBER_OFFSET_INIT(class_devices, "class", "class_devices"); + if (INVALID_MEMBER(class_devices)) + MEMBER_OFFSET_INIT(class_devices, "class", "devices"); + MEMBER_OFFSET_INIT(class_p, "class", "p"); + MEMBER_OFFSET_INIT(class_private_devices, "class_private", + "class_devices"); + MEMBER_OFFSET_INIT(device_knode_class, "device", "knode_class"); + MEMBER_OFFSET_INIT(device_node, "device", "node"); + MEMBER_OFFSET_INIT(device_type, "device", "type"); + MEMBER_OFFSET_INIT(gendisk_dev, "gendisk", "dev"); + if (INVALID_MEMBER(gendisk_dev)) + MEMBER_OFFSET_INIT(gendisk_dev, "gendisk", "__dev"); + MEMBER_OFFSET_INIT(gendisk_kobj, "gendisk", "kobj"); + MEMBER_OFFSET_INIT(gendisk_part0, "gendisk", "part0"); + MEMBER_OFFSET_INIT(gendisk_queue, "gendisk", "queue"); + MEMBER_OFFSET_INIT(hd_struct_dev, "hd_struct", "__dev"); + MEMBER_OFFSET_INIT(klist_k_list, "klist", "k_list"); + MEMBER_OFFSET_INIT(klist_node_n_klist, "klist_node", "n_klist"); + MEMBER_OFFSET_INIT(klist_node_n_node, "klist_node", "n_node"); + MEMBER_OFFSET_INIT(kobject_entry, "kobject", "entry"); + MEMBER_OFFSET_INIT(kset_list, "kset", "list"); + MEMBER_OFFSET_INIT(request_list_count, "request_list", "count"); + MEMBER_OFFSET_INIT(request_queue_in_flight, "request_queue", + "in_flight"); + if (MEMBER_EXISTS("request_queue", "rq")) + MEMBER_OFFSET_INIT(request_queue_rq, "request_queue", "rq"); + else + MEMBER_OFFSET_INIT(request_queue_rq, "request_queue", "root_rl"); + MEMBER_OFFSET_INIT(subsys_private_klist_devices, "subsys_private", + "klist_devices"); + MEMBER_OFFSET_INIT(subsystem_kset, "subsystem", "kset"); + STRUCT_SIZE_INIT(subsystem, "subsystem"); + STRUCT_SIZE_INIT(class_private, "class_private"); + MEMBER_SIZE_INIT(rq_in_flight, "request_queue", "in_flight"); + MEMBER_SIZE_INIT(class_private_devices, "class_private", + "class_devices"); + + dt->flags |= DISKIO_INIT; +} + +static void +diskio_option(void) +{ + diskio_init(); + display_all_diskio(); +} diff --git a/diskdump.c b/diskdump.c new file mode 100644 index 00000000..79fbba71 --- /dev/null +++ b/diskdump.c @@ -0,0 +1,2060 @@ +/* + * diskdump.c + * + * The diskdump module optionally creates either ELF vmcore + * dumpfiles, or compressed dumpfiles derived from the LKCD format. + * In the case of ELF vmcore files, since they are identical to + * netdump dumpfiles, the facilities in netdump.c are used. For + * compressed dumpfiles, the facilities in this file are used. + * + * Copyright (C) 2004-2013 David Anderson + * Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved. + * Copyright (C) 2005 FUJITSU LIMITED + * Copyright (C) 2005 NEC Corporation + * + * 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. + */ + +#include "defs.h" +#include "diskdump.h" + +#define BITMAP_SECT_LEN 4096 + +struct diskdump_data { + char *filename; + ulong flags; /* DISKDUMP_LOCAL, plus anything else... */ + int dfd; /* dumpfile file descriptor */ + FILE *ofp; /* fprintf(dd->ofp, "xxx"); */ + int machine_type; /* machine type identifier */ + + /* header */ + struct disk_dump_header *header; + struct disk_dump_sub_header *sub_header; + struct kdump_sub_header *sub_header_kdump; + + unsigned long long max_mapnr; /* 64bit max_mapnr */ + + size_t data_offset; + int block_size; + int block_shift; + char *bitmap; + off_t bitmap_len; + char *dumpable_bitmap; + int byte, bit; + char *compressed_page; /* copy of compressed page data */ + char *curbufptr; /* ptr to uncompressed page buffer */ + unsigned char *notes_buf; /* copy of elf notes */ + void **nt_prstatus_percpu; + uint num_prstatus_notes; + + /* page cache */ + struct page_cache_hdr { /* header for each cached page */ + uint32_t pg_flags; + uint64_t pg_addr; + char *pg_bufptr; + ulong pg_hit_count; + } page_cache_hdr[DISKDUMP_CACHED_PAGES]; + char *page_cache_buf; /* base of cached buffer pages */ + int evict_index; /* next page to evict */ + ulong evictions; /* total evictions done */ + ulong cached_reads; + ulong *valid_pages; + ulong accesses; +}; + +static struct diskdump_data diskdump_data = { 0 }; +static struct diskdump_data *dd = &diskdump_data; +static int get_dump_level(void); + +ulong *diskdump_flags = &diskdump_data.flags; + +static int __diskdump_memory_dump(FILE *); +static void dump_vmcoreinfo(FILE *); +static void dump_nt_prstatus_offset(FILE *); +static char *vmcoreinfo_read_string(const char *); +static void diskdump_get_osrelease(void); + +/* For split dumpfile */ +static struct diskdump_data **dd_list = NULL; +static int num_dd = 0; +static int num_dumpfiles = 0; + +int dumpfile_is_split(void) +{ + return KDUMP_SPLIT(); +} + +void +map_cpus_to_prstatus_kdump_cmprs(void) +{ + void **nt_ptr; + int online, i, j, nrcpus; + size_t size; + + if (!(online = get_cpus_online()) || (online == kt->cpus)) + return; + + if (CRASHDEBUG(1)) + error(INFO, + "cpus: %d online: %d NT_PRSTATUS notes: %d (remapping)\n", + kt->cpus, online, dd->num_prstatus_notes); + + size = NR_CPUS * sizeof(void *); + + nt_ptr = (void **)GETBUF(size); + BCOPY(dd->nt_prstatus_percpu, nt_ptr, size); + BZERO(dd->nt_prstatus_percpu, size); + + /* + * Re-populate the array with the notes mapping to online cpus + */ + nrcpus = (kt->kernel_NR_CPUS ? kt->kernel_NR_CPUS : NR_CPUS); + + for (i = 0, j = 0; i < nrcpus; i++) { + if (in_cpu_map(ONLINE, i)) { + dd->nt_prstatus_percpu[i] = nt_ptr[j++]; + dd->num_prstatus_notes = + MAX(dd->num_prstatus_notes, i+1); + } + } + + FREEBUF(nt_ptr); +} + +static void +add_diskdump_data(char* name) +{ +#define DDL_SIZE 16 + int i; + int sz = sizeof(void*); + struct diskdump_data *ddp; + + if (dd_list == NULL) { + dd_list = calloc(DDL_SIZE, sz); + num_dd = DDL_SIZE; + } else { + for (i = 0; i < num_dumpfiles; i++) { + ddp = dd_list[i]; + if (same_file(ddp->filename, name)) + error(FATAL, + "split dumpfiles are identical:\n" + " %s\n %s\n", + ddp->filename, name); + if (memcmp(ddp->header, dd->header, + sizeof(struct disk_dump_header))) + error(FATAL, + "split dumpfiles derived from different vmcores:\n" + " %s\n %s\n", + ddp->filename, name); + } + } + + if (num_dumpfiles == num_dd) { + /* expand list */ + struct diskdump_data **tmp; + tmp = calloc(num_dd*2, sz); + memcpy(tmp, dd_list, sz*num_dd); + free(dd_list); + dd_list = tmp; + num_dd *= 2; + } + + dd_list[num_dumpfiles] = dd; + dd->flags |= DUMPFILE_SPLIT; + dd->filename = name; + + if (CRASHDEBUG(1)) + fprintf(fp, "%s: start_pfn=%llu, end_pfn=%llu\n", name, + dd->sub_header_kdump->start_pfn_64, + dd->sub_header_kdump->end_pfn_64); +} + +static void +clean_diskdump_data(void) +{ + int i; + + if (dd_list == NULL) + return; + + for (i=1; ibitmap, nr >> 3, nr & 7); +} + +static inline int +page_is_dumpable(unsigned long nr) +{ + return dd->dumpable_bitmap[nr>>3] & (1 << (nr & 7)); +} + +static inline int +dump_is_partial(const struct disk_dump_header *header) +{ + return header->bitmap_blocks >= + divideup(divideup(dd->max_mapnr, 8), dd->block_size) * 2; +} + +static int +open_dump_file(char *file) +{ + int fd; + + fd = open(file, O_RDONLY); + if (fd < 0) { + error(INFO, "diskdump / compressed kdump: unable to open dump file %s\n", file); + return FALSE; + } + + if (KDUMP_SPLIT()) + dd = calloc(1, sizeof(*dd)); + + dd->dfd = fd; + return TRUE; +} + +void +process_elf32_notes(void *note_buf, unsigned long size_note) +{ + Elf32_Nhdr *nt; + size_t index, len = 0; + int num = 0; + + + for (index = 0; index < size_note; index += len) { + nt = note_buf + index; + + if(nt->n_type == NT_PRSTATUS) { + dd->nt_prstatus_percpu[num] = nt; + num++; + } + len = sizeof(Elf32_Nhdr); + len = roundup(len + nt->n_namesz, 4); + len = roundup(len + nt->n_descsz, 4); + } + + if (num > 0) { + pc->flags2 |= ELF_NOTES; + dd->num_prstatus_notes = num; + } + return; +} + +void +process_elf64_notes(void *note_buf, unsigned long size_note) +{ + Elf64_Nhdr *nt; + size_t index, len = 0; + int num = 0; + + for (index = 0; index < size_note; index += len) { + nt = note_buf + index; + + if(nt->n_type == NT_PRSTATUS) { + dd->nt_prstatus_percpu[num] = nt; + num++; + } + len = sizeof(Elf64_Nhdr); + len = roundup(len + nt->n_namesz, 4); + len = roundup(len + nt->n_descsz, 4); + } + + if (num > 0) { + pc->flags2 |= ELF_NOTES; + dd->num_prstatus_notes = num; + } + return; +} + +void +x86_process_elf_notes(void *note_ptr, unsigned long size_note) +{ + if (machine_type("X86_64")) + process_elf64_notes(note_ptr, size_note); + else if (machine_type("X86")) + process_elf32_notes(note_ptr, size_note); +} + +#if defined(__i386__) && defined(ARM) +/* + * The kdump_sub_header member offsets are different when the crash + * binary is built natively on an ARM host vs. when built with + * "make target=ARM" on an x86/x86_64 host. This is because the + * off_t structure members will be aligned on an 8-byte boundary when + * compiled as an ARM binary -- which will be reflected in the + * kdump_sub_header in a compressed ARM kdump. + * + * When crash is compiled as an x86 binary, these are the + * structure's offsets: + * + * struct kdump_sub_header { + * [0] unsigned long phys_base; + * [4] int dump_level; / header_version 1 and later / + * [8] int split; / header_version 2 and later / + * [12] unsigned long start_pfn; / header_version 2 and later / + * [16] unsigned long end_pfn; / header_version 2 and later / + * [20] off_t offset_vmcoreinfo; / header_version 3 and later / + * [28] unsigned long size_vmcoreinfo; / header_version 3 and later / + * [32] off_t offset_note; / header_version 4 and later / + * [40] unsigned long size_note; / header_version 4 and later / + * [44] off_t offset_eraseinfo; / header_version 5 and later / + * [52] unsigned long size_eraseinfo; / header_version 5 and later / + * [56] unsigned long long start_pfn_64; / header_version 6 and later / + * [64] unsigned long long end_pfn_64; / header_version 6 and later / + * [72] unsigned long long max_mapnr_64; / header_version 6 and later / + * }; + * + * But when compiled on an ARM processor, each 64-bit "off_t" would be pushed + * up to an 8-byte boundary: + * + * struct kdump_sub_header { + * [0] unsigned long phys_base; + * [4] int dump_level; / header_version 1 and later / + * [8] int split; / header_version 2 and later / + * [12] unsigned long start_pfn; / header_version 2 and later / + * [16] unsigned long end_pfn; / header_version 2 and later / + * [24] off_t offset_vmcoreinfo; / header_version 3 and later / + * [32] unsigned long size_vmcoreinfo; / header_version 3 and later / + * [40] off_t offset_note; / header_version 4 and later / + * [48] unsigned long size_note; / header_version 4 and later / + * [56] off_t offset_eraseinfo; / header_version 5 and later / + * [64] unsigned long size_eraseinfo; / header_version 5 and later / + * [72] unsigned long long start_pfn_64; / header_version 6 and later / + * [80] unsigned long long end_pfn_64; / header_version 6 and later / + * [88] unsigned long long max_mapnr_64; / header_version 6 and later / + * }; + * + */ + +struct kdump_sub_header_ARM_target { + unsigned long phys_base; + int dump_level; /* header_version 1 and later */ + int split; /* header_version 2 and later */ + unsigned long start_pfn; /* header_version 2 and later */ + unsigned long end_pfn; /* header_version 2 and later */ + int pad1; + off_t offset_vmcoreinfo; /* header_version 3 and later */ + unsigned long size_vmcoreinfo; /* header_version 3 and later */ + int pad2; + off_t offset_note; /* header_version 4 and later */ + unsigned long size_note; /* header_version 4 and later */ + int pad3; + off_t offset_eraseinfo; /* header_version 5 and later */ + unsigned long size_eraseinfo; /* header_version 5 and later */ + int pad4; + unsigned long long start_pfn_64; /* header_version 6 and later */ + unsigned long long end_pfn_64; /* header_version 6 and later */ + unsigned long long max_mapnr_64; /* header_version 6 and later */ +}; + +static void +arm_kdump_header_adjust(int header_version) +{ + struct kdump_sub_header *kdsh; + struct kdump_sub_header_ARM_target *kdsh_ARM_target; + + kdsh = dd->sub_header_kdump; + kdsh_ARM_target = (struct kdump_sub_header_ARM_target *)kdsh; + + if (header_version >= 3) { + kdsh->offset_vmcoreinfo = kdsh_ARM_target->offset_vmcoreinfo; + kdsh->size_vmcoreinfo = kdsh_ARM_target->size_vmcoreinfo; + } + if (header_version >= 4) { + kdsh->offset_note = kdsh_ARM_target->offset_note; + kdsh->size_note = kdsh_ARM_target->size_note; + } + if (header_version >= 5) { + kdsh->offset_eraseinfo = kdsh_ARM_target->offset_eraseinfo; + kdsh->size_eraseinfo = kdsh_ARM_target->size_eraseinfo; + } + if (header_version >= 6) { + kdsh->start_pfn_64 = kdsh_ARM_target->start_pfn_64; + kdsh->end_pfn_64 = kdsh_ARM_target->end_pfn_64; + kdsh->max_mapnr_64 = kdsh_ARM_target->max_mapnr_64; + } else { + kdsh->start_pfn_64 = kdsh_ARM_target->start_pfn; + kdsh->end_pfn_64 = kdsh_ARM_target->end_pfn; + kdsh->max_mapnr_64 = dd->max_mapnr; + } +} +#endif /* __i386__ && ARM */ + +static int +read_dump_header(char *file) +{ + struct disk_dump_header *header = NULL; + struct disk_dump_sub_header *sub_header = NULL; + struct kdump_sub_header *sub_header_kdump = NULL; + size_t size; + off_t bitmap_len; + char *bufptr; + size_t len; + ssize_t bytes_read; + int block_size = (int)sysconf(_SC_PAGESIZE); + off_t offset; + const off_t failed = (off_t)-1; + ulong pfn; + int i, j, max_sect_len; + int is_split = 0; + + if (block_size < 0) + return FALSE; + +restart: + if ((header = realloc(header, block_size)) == NULL) + error(FATAL, "diskdump / compressed kdump: cannot malloc block_size buffer\n"); + + if (FLAT_FORMAT()) { + if (!read_flattened_format(dd->dfd, 0, header, block_size)) { + error(FATAL, "diskdump / compressed kdump: cannot read header\n"); + goto err; + } + } else { + if (lseek(dd->dfd, 0, SEEK_SET) == failed) { + if (CRASHDEBUG(1)) + error(INFO, "diskdump / compressed kdump: cannot lseek dump header\n"); + goto err; + } + if (read(dd->dfd, header, block_size) < block_size) { + if (CRASHDEBUG(1)) + error(INFO, "diskdump / compressed kdump: cannot read dump header\n"); + goto err; + } + } + + /* validate dump header */ + if (!memcmp(header->signature, DISK_DUMP_SIGNATURE, + sizeof(header->signature))) { + dd->flags |= DISKDUMP_LOCAL; + } else if (!memcmp(header->signature, KDUMP_SIGNATURE, + sizeof(header->signature))) { + dd->flags |= KDUMP_CMPRS_LOCAL; + if (header->header_version >= 1) + dd->flags |= ERROR_EXCLUDED; + } else { + if (CRASHDEBUG(1)) + error(INFO, + "diskdump / compressed kdump: dump does not have panic dump header\n"); + goto err; + } + + if (CRASHDEBUG(1)) + fprintf(fp, "%s: header->utsname.machine: %s\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump", + header->utsname.machine); + + if (STRNEQ(header->utsname.machine, "i686") && + machine_type_mismatch(file, "X86", NULL, 0)) + goto err; + else if (STRNEQ(header->utsname.machine, "x86_64") && + machine_type_mismatch(file, "X86_64", NULL, 0)) + goto err; + else if (STRNEQ(header->utsname.machine, "ia64") && + machine_type_mismatch(file, "IA64", NULL, 0)) + goto err; + else if (STREQ(header->utsname.machine, "ppc") && + machine_type_mismatch(file, "PPC", NULL, 0)) + goto err; + else if (STREQ(header->utsname.machine, "ppc64") && + machine_type_mismatch(file, "PPC64", NULL, 0)) + goto err; + else if (STRNEQ(header->utsname.machine, "arm") && + machine_type_mismatch(file, "ARM", NULL, 0)) + goto err; + else if (STRNEQ(header->utsname.machine, "s390x") && + machine_type_mismatch(file, "S390X", NULL, 0)) + goto err; + else if (STRNEQ(header->utsname.machine, "aarch64") && + machine_type_mismatch(file, "ARM64", NULL, 0)) + goto err; + + if (header->block_size != block_size) { + block_size = header->block_size; + if (CRASHDEBUG(1)) + fprintf(fp, + "retrying with different block/page size: %d\n", + header->block_size); + goto restart; + } + dd->block_size = header->block_size; + dd->block_shift = ffs(header->block_size) - 1; + + if ((DISKDUMP_VALID() && + (sizeof(*header) + sizeof(void *) * header->nr_cpus > block_size)) || + header->nr_cpus <= 0) { + error(WARNING, "%s: invalid nr_cpus value: %d\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump", + header->nr_cpus); + if (!machine_type("S390") && !machine_type("S390X") && + !machine_type("X86") && !machine_type("X86_64")) { + if (DISKDUMP_VALID()) + goto err; + } + } + + /* read sub header */ + offset = (off_t)block_size; + + if (DISKDUMP_VALID()) { + if ((sub_header = malloc(block_size)) == NULL) + error(FATAL, "diskdump: cannot malloc sub_header buffer\n"); + + if (FLAT_FORMAT()) { + if (!read_flattened_format(dd->dfd, offset, sub_header, block_size)) { + error(INFO, "diskdump: cannot read dump sub header\n"); + goto err; + } + } else { + if (lseek(dd->dfd, offset, SEEK_SET) == failed) { + error(INFO, "diskdump: cannot lseek dump sub header\n"); + goto err; + } + if (read(dd->dfd, sub_header, block_size) < block_size) { + error(INFO, "diskdump: cannot read dump sub header\n"); + goto err; + } + } + dd->sub_header = sub_header; + + /* the 64bit max_mapnr only exists in sub-header of compressed + * kdump file, if it's not a compressed kdump file, we have to + * use the old 32bit max_mapnr in dumpfile header. + * max_mapnr may be truncated here. + */ + dd->max_mapnr = header->max_mapnr; + } else if (KDUMP_CMPRS_VALID()) { + if ((sub_header_kdump = malloc(block_size)) == NULL) + error(FATAL, "compressed kdump: cannot malloc sub_header_kdump buffer\n"); + + if (FLAT_FORMAT()) { + if (!read_flattened_format(dd->dfd, offset, sub_header_kdump, block_size)) { + error(INFO, "compressed kdump: cannot read dump sub header\n"); + goto err; + } + } else { + if (lseek(dd->dfd, offset, SEEK_SET) == failed) { + error(INFO, "compressed kdump: cannot lseek dump sub header\n"); + goto err; + } + if (read(dd->dfd, sub_header_kdump, block_size) < block_size) { + error(INFO, "compressed kdump: cannot read dump sub header\n"); + goto err; + } + } + dd->sub_header_kdump = sub_header_kdump; + +#if defined(__i386__) && defined(ARM) + arm_kdump_header_adjust(header->header_version); +#endif + /* use 64bit max_mapnr in compressed kdump file sub-header */ + if (header->header_version >= 6) + dd->max_mapnr = dd->sub_header_kdump->max_mapnr_64; + else { + dd->sub_header_kdump->start_pfn_64 + = dd->sub_header_kdump->start_pfn; + dd->sub_header_kdump->end_pfn_64 + = dd->sub_header_kdump->end_pfn; + } + } + + if (header->header_version < 6) + dd->max_mapnr = header->max_mapnr; + + /* read memory bitmap */ + bitmap_len = block_size * header->bitmap_blocks; + dd->bitmap_len = bitmap_len; + + offset = (off_t)block_size * (1 + header->sub_hdr_size); + + if ((dd->bitmap = malloc(bitmap_len)) == NULL) + error(FATAL, "%s: cannot malloc bitmap buffer\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); + + dd->dumpable_bitmap = calloc(bitmap_len, 1); + + if (CRASHDEBUG(8)) + fprintf(fp, "%s: memory bitmap offset: %llx\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump", + (ulonglong)offset); + + if (FLAT_FORMAT()) { + if (!read_flattened_format(dd->dfd, offset, dd->bitmap, bitmap_len)) { + error(INFO, "%s: cannot read memory bitmap\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); + goto err; + } + } else { + if (lseek(dd->dfd, offset, SEEK_SET) == failed) { + error(INFO, "%s: cannot lseek memory bitmap\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); + goto err; + } + bufptr = dd->bitmap; + len = bitmap_len; + while (len) { + bytes_read = read(dd->dfd, bufptr, len); + if (bytes_read < 0) { + error(INFO, "%s: cannot read memory bitmap\n", + DISKDUMP_VALID() ? "diskdump" + : "compressed kdump"); + goto err; + } + len -= bytes_read; + bufptr += bytes_read; + } + } + + if (dump_is_partial(header)) + memcpy(dd->dumpable_bitmap, dd->bitmap + bitmap_len/2, + bitmap_len/2); + else + memcpy(dd->dumpable_bitmap, dd->bitmap, bitmap_len); + + dd->data_offset + = (1 + header->sub_hdr_size + header->bitmap_blocks) + * header->block_size; + + dd->header = header; + + if (machine_type("ARM")) + dd->machine_type = EM_ARM; + else if (machine_type("X86")) + dd->machine_type = EM_386; + else if (machine_type("X86_64")) + dd->machine_type = EM_X86_64; + else if (machine_type("IA64")) + dd->machine_type = EM_IA_64; + else if (machine_type("PPC")) + dd->machine_type = EM_PPC; + else if (machine_type("PPC64")) + dd->machine_type = EM_PPC64; + else if (machine_type("S390X")) + dd->machine_type = EM_S390; + else if (machine_type("ARM64")) + dd->machine_type = EM_AARCH64; + else { + error(INFO, "%s: unsupported machine type: %s\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump", + MACHINE_TYPE); + goto err; + } + + /* process elf notes data */ + if (KDUMP_CMPRS_VALID() && !(dd->flags & NO_ELF_NOTES) && + (dd->header->header_version >= 4) && + (sub_header_kdump->offset_note) && + (sub_header_kdump->size_note) && (machdep->process_elf_notes)) { + size = sub_header_kdump->size_note; + offset = sub_header_kdump->offset_note; + + if ((dd->notes_buf = malloc(size)) == NULL) + error(FATAL, "compressed kdump: cannot malloc notes" + " buffer\n"); + + if ((dd->nt_prstatus_percpu = malloc(NR_CPUS * sizeof(void*))) == NULL) + error(FATAL, "compressed kdump: cannot malloc pointer" + " to NT_PRSTATUS notes\n"); + + if (FLAT_FORMAT()) { + if (!read_flattened_format(dd->dfd, offset, dd->notes_buf, size)) { + error(INFO, "compressed kdump: cannot read notes data" + "\n"); + goto err; + } + } else { + if (lseek(dd->dfd, offset, SEEK_SET) == failed) { + error(INFO, "compressed kdump: cannot lseek notes data\n"); + goto err; + } + if (read(dd->dfd, dd->notes_buf, size) < size) { + error(INFO, "compressed kdump: cannot read notes data" + "\n"); + goto err; + } + } + + machdep->process_elf_notes(dd->notes_buf, size); + } + + /* Check if dump file contains erasesinfo data */ + if (KDUMP_CMPRS_VALID() && (dd->header->header_version >= 5) && + (sub_header_kdump->offset_eraseinfo) && + (sub_header_kdump->size_eraseinfo)) + pc->flags2 |= ERASEINFO_DATA; + + if (KDUMP_CMPRS_VALID() && (dd->header->header_version >= 3) && + dd->sub_header_kdump->offset_vmcoreinfo && + dd->sub_header_kdump->size_vmcoreinfo) + pc->flags2 |= VMCOREINFO; + + /* For split dumpfile */ + if (KDUMP_CMPRS_VALID()) { + is_split = ((dd->header->header_version >= 2) && + (sub_header_kdump->split)); + + if ((is_split && (num_dumpfiles != 0) && (dd_list == NULL))|| + (!is_split && (num_dumpfiles != 0))) { + clean_diskdump_data(); + goto err; + } + + if (is_split) + add_diskdump_data(file); + + num_dumpfiles++; + } + + if (!is_split) { + max_sect_len = divideup(dd->max_mapnr, BITMAP_SECT_LEN); + pfn = 0; + dd->filename = file; + } + else { + unsigned long long start = sub_header_kdump->start_pfn_64; + unsigned long long end = sub_header_kdump->end_pfn_64; + max_sect_len = divideup(end - start + 1, BITMAP_SECT_LEN); + pfn = start; + } + + dd->valid_pages = calloc(sizeof(ulong), max_sect_len + 1); + for (i = 1; i < max_sect_len + 1; i++) { + dd->valid_pages[i] = dd->valid_pages[i - 1]; + for (j = 0; j < BITMAP_SECT_LEN; j++, pfn++) + if (page_is_dumpable(pfn)) + dd->valid_pages[i]++; + } + + return TRUE; + +err: + free(header); + if (sub_header) + free(sub_header); + if (sub_header_kdump) + free(sub_header_kdump); + if (dd->bitmap) + free(dd->bitmap); + if (dd->dumpable_bitmap) + free(dd->dumpable_bitmap); + if (dd->notes_buf) + free(dd->notes_buf); + if (dd->nt_prstatus_percpu) + free(dd->nt_prstatus_percpu); + + dd->flags &= ~(DISKDUMP_LOCAL|KDUMP_CMPRS_LOCAL); + pc->flags2 &= ~ELF_NOTES; + return FALSE; +} + +static ulong +pfn_to_pos(ulong pfn) +{ + ulong desc_pos, j, valid; + ulong p1, p2; + + if (KDUMP_SPLIT()) { + p1 = pfn - dd->sub_header_kdump->start_pfn_64; + p2 = round(p1, BITMAP_SECT_LEN) + + dd->sub_header_kdump->start_pfn_64; + } + else { + p1 = pfn; + p2 = round(pfn, BITMAP_SECT_LEN); + } + + valid = dd->valid_pages[p1 / BITMAP_SECT_LEN]; + + for (j = p2, desc_pos = valid; j <= pfn; j++) + if (page_is_dumpable(j)) + desc_pos++; + + return desc_pos; +} + + +/* + * Determine whether a file is a diskdump creation, and if TRUE, + * initialize the diskdump_data structure based upon the contents + * of the diskdump header data. + */ +int +is_diskdump(char *file) +{ + int sz, i; + + if (!open_dump_file(file) || !read_dump_header(file)) + return FALSE; + + sz = dd->block_size * (DISKDUMP_CACHED_PAGES); + if ((dd->page_cache_buf = malloc(sz)) == NULL) + error(FATAL, "%s: cannot malloc compressed page_cache_buf\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); + + for (i = 0; i < DISKDUMP_CACHED_PAGES; i++) + dd->page_cache_hdr[i].pg_bufptr = + &dd->page_cache_buf[i * dd->block_size]; + + if ((dd->compressed_page = (char *)malloc(dd->block_size)) == NULL) + error(FATAL, "%s: cannot malloc compressed page space\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); + + if (CRASHDEBUG(1)) + __diskdump_memory_dump(fp); + + if (pc->flags2 & GET_OSRELEASE) + diskdump_get_osrelease(); + +#ifdef LZO + if (lzo_init() == LZO_E_OK) + dd->flags |= LZO_SUPPORTED; +#endif + +#ifdef SNAPPY + dd->flags |= SNAPPY_SUPPORTED; +#endif + + if ((pc->flags2 & GET_LOG) && KDUMP_CMPRS_VALID()) { + pc->dfd = dd->dfd; + pc->readmem = read_diskdump; + pc->flags |= DISKDUMP; + get_log_from_vmcoreinfo(file, vmcoreinfo_read_string); + } + + return TRUE; +} + +/* + * Perform any post-dumpfile determination stuff here. + * At a minimum + */ +int +diskdump_init(char *unused, FILE *fptr) +{ + if (!DISKDUMP_VALID() && !KDUMP_CMPRS_VALID()) + return FALSE; + + dd->ofp = fptr; + return TRUE; +} + +/* + * Get the relocational offset from the sub header of kdump. + */ +int +diskdump_phys_base(unsigned long *phys_base) +{ + if (KDUMP_CMPRS_VALID()) { + *phys_base = dd->sub_header_kdump->phys_base; + return TRUE; + } + + return FALSE; +} + +/* + * Check whether paddr is already cached. + */ +static int +page_is_cached(physaddr_t paddr) +{ + int i; + struct page_cache_hdr *pgc; + + dd->accesses++; + + for (i = 0; i < DISKDUMP_CACHED_PAGES; i++) { + + pgc = &dd->page_cache_hdr[i]; + + if (!DISKDUMP_VALID_PAGE(pgc->pg_flags)) + continue; + + if (pgc->pg_addr == paddr) { + pgc->pg_hit_count++; + dd->curbufptr = pgc->pg_bufptr; + dd->cached_reads++; + return TRUE; + } + } + return FALSE; +} + +/* + * Translate physical address in paddr to PFN number. This means normally that + * we just shift paddr by some constant. Some architectures need special + * handling for this, however. + */ +static ulong +paddr_to_pfn(physaddr_t paddr) +{ +#ifdef ARM + /* + * In ARM, PFN 0 means first page in kernel direct-mapped view. + * This is also first page in mem_map as well. + */ + return (paddr - machdep->machspec->phys_base) >> dd->block_shift; +#else + return paddr >> dd->block_shift; +#endif +} + +/* + * Cache the page's data. + * + * If an empty page cache location is available, take it. Otherwise, evict + * the entry indexed by evict_index, and then bump evict index. The hit_count + * is only gathered for dump_diskdump_environment(). + * + * If the page is compressed, uncompress it into the selected page cache entry. + * If the page is raw, just copy it into the selected page cache entry. + * If all works OK, update diskdump->curbufptr to point to the page's + * uncompressed data. + */ +static int +cache_page(physaddr_t paddr) +{ + int i, ret; + int found; + ulong pfn; + ulong desc_pos; + off_t seek_offset; + page_desc_t pd; + const int block_size = dd->block_size; + const off_t failed = (off_t)-1; + ulong retlen; + + for (i = found = 0; i < DISKDUMP_CACHED_PAGES; i++) { + if (DISKDUMP_VALID_PAGE(dd->page_cache_hdr[i].pg_flags)) + continue; + found = TRUE; + break; + } + + if (!found) { + i = dd->evict_index; + dd->page_cache_hdr[i].pg_hit_count = 0; + dd->evict_index = + (dd->evict_index+1) % DISKDUMP_CACHED_PAGES; + dd->evictions++; + } + + dd->page_cache_hdr[i].pg_flags = 0; + dd->page_cache_hdr[i].pg_addr = paddr; + dd->page_cache_hdr[i].pg_hit_count++; + + /* find page descriptor */ + pfn = paddr_to_pfn(paddr); + desc_pos = pfn_to_pos(pfn); + seek_offset = dd->data_offset + + (off_t)(desc_pos - 1)*sizeof(page_desc_t); + + /* read page descriptor */ + if (FLAT_FORMAT()) { + if (!read_flattened_format(dd->dfd, seek_offset, &pd, sizeof(pd))) + return READ_ERROR; + } else { + if (lseek(dd->dfd, seek_offset, SEEK_SET) == failed) + return SEEK_ERROR; + if (read(dd->dfd, &pd, sizeof(pd)) != sizeof(pd)) + return READ_ERROR; + } + + /* sanity check */ + if (pd.size > block_size) + return READ_ERROR; + + /* read page data */ + if (FLAT_FORMAT()) { + if (!read_flattened_format(dd->dfd, pd.offset, dd->compressed_page, pd.size)) + return READ_ERROR; + } else { + if (lseek(dd->dfd, pd.offset, SEEK_SET) == failed) + return SEEK_ERROR; + if (read(dd->dfd, dd->compressed_page, pd.size) != pd.size) + return READ_ERROR; + } + + if (pd.flags & DUMP_DH_COMPRESSED_ZLIB) { + retlen = block_size; + ret = uncompress((unsigned char *)dd->page_cache_hdr[i].pg_bufptr, + &retlen, + (unsigned char *)dd->compressed_page, + pd.size); + if ((ret != Z_OK) || (retlen != block_size)) { + error(INFO, "%s: uncompress failed: %d\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump", + ret); + return READ_ERROR; + } + } else if (pd.flags & DUMP_DH_COMPRESSED_LZO) { + + if (!(dd->flags & LZO_SUPPORTED)) { + error(INFO, "%s: uncompress failed: no lzo compression support\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); + return READ_ERROR; + } + +#ifdef LZO + retlen = block_size; + ret = lzo1x_decompress_safe((unsigned char *)dd->compressed_page, + pd.size, + (unsigned char *)dd->page_cache_hdr[i].pg_bufptr, + &retlen, + LZO1X_MEM_DECOMPRESS); + if ((ret != LZO_E_OK) || (retlen != block_size)) { + error(INFO, "%s: uncompress failed: %d\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump", + ret); + return READ_ERROR; + } +#endif + } else if (pd.flags & DUMP_DH_COMPRESSED_SNAPPY) { + + if (!(dd->flags & SNAPPY_SUPPORTED)) { + error(INFO, "%s: uncompress failed: no snappy compression support\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump"); + return READ_ERROR; + } + +#ifdef SNAPPY + ret = snappy_uncompressed_length((char *)dd->compressed_page, + pd.size, (size_t *)&retlen); + if (ret != SNAPPY_OK) { + error(INFO, "%s: uncompress failed: %d\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump", + ret); + return READ_ERROR; + } + + ret = snappy_uncompress((char *)dd->compressed_page, pd.size, + (char *)dd->page_cache_hdr[i].pg_bufptr, + (size_t *)&retlen); + if ((ret != SNAPPY_OK) || (retlen != block_size)) { + error(INFO, "%s: uncompress failed: %d\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump", + ret); + return READ_ERROR; + } +#endif + } else + memcpy(dd->page_cache_hdr[i].pg_bufptr, + dd->compressed_page, block_size); + + dd->page_cache_hdr[i].pg_flags |= PAGE_VALID; + dd->curbufptr = dd->page_cache_hdr[i].pg_bufptr; + + return TRUE; +} + +/* + * Read from a diskdump-created dumpfile. + */ +int +read_diskdump(int fd, void *bufptr, int cnt, ulong addr, physaddr_t paddr) +{ + int ret; + physaddr_t curpaddr; + ulong pfn, page_offset; + + pfn = paddr_to_pfn(paddr); + + if (KDUMP_SPLIT()) { + /* Find proper dd */ + int i; + unsigned long long start_pfn; + unsigned long long end_pfn; + + for (i=0; isub_header_kdump->start_pfn_64; + end_pfn = dd_list[i]->sub_header_kdump->end_pfn_64; + if ((pfn >= start_pfn) && (pfn <= end_pfn)) { + dd = dd_list[i]; + break; + } + } + + if (i == num_dumpfiles) { + if (CRASHDEBUG(8)) + fprintf(fp, "read_diskdump: SEEK_ERROR: " + "paddr/pfn %llx/%lx beyond last dumpfile\n", + (ulonglong)paddr, pfn); + return SEEK_ERROR; + } + } + + curpaddr = paddr & ~((physaddr_t)(dd->block_size-1)); + page_offset = paddr & ((physaddr_t)(dd->block_size-1)); + + if ((pfn >= dd->max_mapnr) || !page_is_ram(pfn)) { + if (CRASHDEBUG(8)) { + fprintf(fp, "read_diskdump: SEEK_ERROR: " + "paddr/pfn: %llx/%lx ", + (ulonglong)paddr, pfn); + if (pfn >= dd->max_mapnr) + fprintf(fp, "max_mapnr: %llx\n", + dd->max_mapnr); + else + fprintf(fp, "!page_is_ram\n"); + } + + return SEEK_ERROR; + } + + if (!page_is_dumpable(pfn)) { + if ((dd->flags & (ZERO_EXCLUDED|ERROR_EXCLUDED)) == + ERROR_EXCLUDED) { + if (CRASHDEBUG(8)) + fprintf(fp, "read_diskdump: PAGE_EXCLUDED: " + "paddr/pfn: %llx/%lx\n", + (ulonglong)paddr, pfn); + return PAGE_EXCLUDED; + } + if (CRASHDEBUG(8)) + fprintf(fp, "read_diskdump: zero-fill: " + "paddr/pfn: %llx/%lx\n", + (ulonglong)paddr, pfn); + memset(bufptr, 0, cnt); + return cnt; + } + + if (!page_is_cached(curpaddr)) { + if (CRASHDEBUG(8)) + fprintf(fp, "read_diskdump: paddr/pfn: %llx/%lx" + " -> cache physical page: %llx\n", + (ulonglong)paddr, pfn, (ulonglong)curpaddr); + + if ((ret = cache_page(curpaddr)) < 0) { + if (CRASHDEBUG(8)) + fprintf(fp, "read_diskdump: " + "%s: cannot cache page: %llx\n", + ret == SEEK_ERROR ? + "SEEK_ERROR" : "READ_ERROR", + (ulonglong)curpaddr); + return ret; + } + } else if (CRASHDEBUG(8)) + fprintf(fp, "read_diskdump: paddr/pfn: %llx/%lx" + " -> physical page is cached: %llx\n", + (ulonglong)paddr, pfn, (ulonglong)curpaddr); + + memcpy(bufptr, dd->curbufptr + page_offset, cnt); + return cnt; +} + +/* + * Write to a diskdump-created dumpfile. + */ +int +write_diskdump(int fd, void *bufptr, int cnt, ulong addr, physaddr_t paddr) +{ + return 0; +} + +ulong +get_diskdump_panic_task(void) +{ + int i; + + if ((!DISKDUMP_VALID() && !KDUMP_CMPRS_VALID()) + || !get_active_set()) + return NO_TASK; + + if (DISKDUMP_VALID()) + return (ulong)dd->header->tasks[dd->header->current_cpu]; + + if (KDUMP_CMPRS_VALID()) { + if (kernel_symbol_exists("crashing_cpu") && + cpu_map_addr("online")) { + get_symbol_data("crashing_cpu", sizeof(int), &i); + if ((i >= 0) && in_cpu_map(ONLINE, i)) { + if (CRASHDEBUG(1)) + error(INFO, "get_diskdump_panic_task: " + "active_set[%d]: %lx\n", + i, tt->active_set[i]); + return (tt->active_set[i]); + } + } + } + + return NO_TASK; +} + +extern void get_netdump_regs_x86(struct bt_info *, ulong *, ulong *); +extern void get_netdump_regs_x86_64(struct bt_info *, ulong *, ulong *); + +static void +get_diskdump_regs_ppc(struct bt_info *bt, ulong *eip, ulong *esp) +{ + Elf32_Nhdr *note; + int len; + + if (KDUMP_CMPRS_VALID()) + ppc_relocate_nt_prstatus_percpu(dd->nt_prstatus_percpu, + &dd->num_prstatus_notes); + if (KDUMP_CMPRS_VALID() && + (bt->task == tt->panic_task || + (is_task_active(bt->task) && dd->num_prstatus_notes > 1))) { + note = (Elf32_Nhdr*) dd->nt_prstatus_percpu[bt->tc->processor]; + if (!note) + error(FATAL, + "cannot determine NT_PRSTATUS ELF note " + "for %s task: %lx\n", + (bt->task == tt->panic_task) ? + "panic" : "active", bt->task); + len = sizeof(Elf32_Nhdr); + len = roundup(len + note->n_namesz, 4); + bt->machdep = (void *)((char *)note + len + + MEMBER_OFFSET("elf_prstatus", "pr_reg")); + } + + machdep->get_stack_frame(bt, eip, esp); +} + +static void +get_diskdump_regs_ppc64(struct bt_info *bt, ulong *eip, ulong *esp) +{ + if ((bt->task == tt->panic_task) && DISKDUMP_VALID()) + bt->machdep = &dd->sub_header->elf_regs; + + machdep->get_stack_frame(bt, eip, esp); +} + +static void +get_diskdump_regs_arm(struct bt_info *bt, ulong *eip, ulong *esp) +{ + machdep->get_stack_frame(bt, eip, esp); +} + +static void +get_diskdump_regs_arm64(struct bt_info *bt, ulong *eip, ulong *esp) +{ + machdep->get_stack_frame(bt, eip, esp); +} + +/* + * Send the request to the proper architecture hander. + */ + +void +get_diskdump_regs(struct bt_info *bt, ulong *eip, ulong *esp) +{ + switch (dd->machine_type) + { + case EM_ARM: + get_diskdump_regs_arm(bt, eip, esp); + break; + + case EM_386: + return get_netdump_regs_x86(bt, eip, esp); + break; + + case EM_IA_64: + /* For normal backtraces, this information will be obtained + * frome the switch_stack structure, which is pointed to by + * the thread.ksp field of the task_struct. But it's still + * needed by the "bt -t" option. + */ + machdep->get_stack_frame(bt, eip, esp); + break; + + case EM_PPC: + return get_diskdump_regs_ppc(bt, eip, esp); + break; + + case EM_PPC64: + return get_diskdump_regs_ppc64(bt, eip, esp); + break; + + case EM_X86_64: + return get_netdump_regs_x86_64(bt, eip, esp); + break; + + case EM_S390: + return machdep->get_stack_frame(bt, eip, esp); + break; + + case EM_AARCH64: + get_diskdump_regs_arm64(bt, eip, esp); + break; + + default: + error(FATAL, "%s: unsupported machine type: %s\n", + DISKDUMP_VALID() ? "diskdump" : "compressed kdump", + MACHINE_TYPE); + } +} + +/* + * Return the processor page size. + */ +uint +diskdump_page_size(void) +{ + if (!DISKDUMP_VALID() && !KDUMP_CMPRS_VALID()) + return 0; + + return dd->header->block_size; +} + +/* + * diskdump_free_memory(), and diskdump_memory_used() + * are debug only, and probably unnecessary to implement. + */ +int +diskdump_free_memory(void) +{ + return 0; +} + +int +diskdump_memory_used(void) +{ + return 0; +} + +static void +dump_vmcoreinfo(FILE *fp) +{ + char *buf = NULL; + unsigned long i = 0; + unsigned long size_vmcoreinfo = dd->sub_header_kdump->size_vmcoreinfo; + off_t offset = dd->sub_header_kdump->offset_vmcoreinfo; + const off_t failed = (off_t)-1; + + if ((buf = malloc(size_vmcoreinfo)) == NULL) { + error(FATAL, "compressed kdump: cannot malloc vmcoreinfo" + " buffer\n"); + } + + if (FLAT_FORMAT()) { + if (!read_flattened_format(dd->dfd, offset, buf, size_vmcoreinfo)) { + error(INFO, "compressed kdump: cannot read vmcoreinfo data\n"); + goto err; + } + } else { + if (lseek(dd->dfd, offset, SEEK_SET) == failed) { + error(INFO, "compressed kdump: cannot lseek dump vmcoreinfo\n"); + goto err; + } + if (read(dd->dfd, buf, size_vmcoreinfo) < size_vmcoreinfo) { + error(INFO, "compressed kdump: cannot read vmcoreinfo data\n"); + goto err; + } + } + + fprintf(fp, " "); + for (i = 0; i < size_vmcoreinfo; i++) { + fprintf(fp, "%c", buf[i]); + if (buf[i] == '\n') + fprintf(fp, " "); + } + if (buf[i - 1] != '\n') + fprintf(fp, "\n"); +err: + if (buf) + free(buf); + return; +} + +static void +dump_eraseinfo(FILE *fp) +{ + char *buf = NULL; + unsigned long i = 0; + unsigned long size_eraseinfo = dd->sub_header_kdump->size_eraseinfo; + off_t offset = dd->sub_header_kdump->offset_eraseinfo; + const off_t failed = (off_t)-1; + + if ((buf = malloc(size_eraseinfo)) == NULL) { + error(FATAL, "compressed kdump: cannot malloc eraseinfo" + " buffer\n"); + } + + if (FLAT_FORMAT()) { + if (!read_flattened_format(dd->dfd, offset, buf, size_eraseinfo)) { + error(INFO, "compressed kdump: cannot read eraseinfo data\n"); + goto err; + } + } else { + if (lseek(dd->dfd, offset, SEEK_SET) == failed) { + error(INFO, "compressed kdump: cannot lseek dump eraseinfo\n"); + goto err; + } + if (read(dd->dfd, buf, size_eraseinfo) < size_eraseinfo) { + error(INFO, "compressed kdump: cannot read eraseinfo data\n"); + goto err; + } + } + + fprintf(fp, " "); + for (i = 0; i < size_eraseinfo; i++) { + fprintf(fp, "%c", buf[i]); + if (buf[i] == '\n') + fprintf(fp, " "); + } + if (buf[i - 1] != '\n') + fprintf(fp, "\n"); +err: + if (buf) + free(buf); + return; +} + +static void +dump_nt_prstatus_offset(FILE *fp) +{ + struct kdump_sub_header *sub_header_kdump = dd->sub_header_kdump; + size_t size; + off_t offset; + Elf32_Nhdr *note32 = NULL; + Elf64_Nhdr *note64 = NULL; + size_t tot, len = 0; + int cnt; + + if (KDUMP_CMPRS_VALID() && !(dd->flags & NO_ELF_NOTES) && + (dd->header->header_version >= 4) && + (sub_header_kdump->offset_note) && + (sub_header_kdump->size_note) && (machdep->process_elf_notes)) { + size = sub_header_kdump->size_note; + offset = sub_header_kdump->offset_note; + + fprintf(fp, " NT_PRSTATUS_offset: "); + for (tot = cnt = 0; tot < size; tot += len) { + if (machine_type("X86_64") || machine_type("S390X") || + machine_type("ARM64")) { + note64 = (void *)dd->notes_buf + tot; + len = sizeof(Elf64_Nhdr); + len = roundup(len + note64->n_namesz, 4); + len = roundup(len + note64->n_descsz, 4); + + if (note64->n_type == NT_PRSTATUS) { + fprintf(fp, "%s%lx\n", + (tot == 0) ? "" : " ", + (ulong)(offset + tot)); + cnt++; + } + + } else if (machine_type("X86") || machine_type("PPC")) { + note32 = (void *)dd->notes_buf + tot; + len = sizeof(Elf32_Nhdr); + len = roundup(len + note32->n_namesz, 4); + len = roundup(len + note32->n_descsz, 4); + + if (note32->n_type == NT_PRSTATUS) { + fprintf(fp, "%s%lx\n", + (tot == 0) ? "" : " ", + (ulong)(offset + tot)); + cnt++; + } + } + } + if (!cnt) + fprintf(fp, "\n"); + } +} + +/* + * This function is dump-type independent, and could be used + * to dump the diskdump_data structure contents and perhaps + * the diskdump header data. + */ +int +__diskdump_memory_dump(FILE *fp) +{ + int i, others, dump_level; + struct disk_dump_header *dh; + struct disk_dump_sub_header *dsh; + struct kdump_sub_header *kdsh; + ulong *tasks; + + if (FLAT_FORMAT()) + dump_flat_header(fp); + + fprintf(fp, "diskdump_data: \n"); + fprintf(fp, " filename: %s\n", dd->filename); + fprintf(fp, " flags: %lx (", dd->flags); + others = 0; + if (dd->flags & DISKDUMP_LOCAL) + fprintf(fp, "%sDISKDUMP_LOCAL", others++ ? "|" : ""); + if (dd->flags & KDUMP_CMPRS_LOCAL) + fprintf(fp, "%sKDUMP_CMPRS_LOCAL", others++ ? "|" : ""); + if (dd->flags & ERROR_EXCLUDED) + fprintf(fp, "%sERROR_EXCLUDED", others++ ? "|" : ""); + if (dd->flags & ZERO_EXCLUDED) + fprintf(fp, "%sZERO_EXCLUDED", others++ ? "|" : ""); + if (dd->flags & NO_ELF_NOTES) + fprintf(fp, "%sNO_ELF_NOTES", others++ ? "|" : ""); + if (dd->flags & LZO_SUPPORTED) + fprintf(fp, "%sLZO_SUPPORTED", others++ ? "|" : ""); + if (dd->flags & SNAPPY_SUPPORTED) + fprintf(fp, "%sSNAPPY_SUPPORTED", others++ ? "|" : ""); + fprintf(fp, ") %s\n", FLAT_FORMAT() ? "[FLAT]" : ""); + fprintf(fp, " dfd: %d\n", dd->dfd); + fprintf(fp, " ofp: %lx\n", (ulong)dd->ofp); + fprintf(fp, " machine_type: %d ", dd->machine_type); + switch (dd->machine_type) + { + case EM_ARM: + fprintf(fp, "(EM_ARM)\n"); break; + case EM_386: + fprintf(fp, "(EM_386)\n"); break; + case EM_X86_64: + fprintf(fp, "(EM_X86_64)\n"); break; + case EM_IA_64: + fprintf(fp, "(EM_IA_64)\n"); break; + case EM_PPC: + fprintf(fp, "(EM_PPC)\n"); break; + case EM_PPC64: + fprintf(fp, "(EM_PPC64)\n"); break; + case EM_S390: + fprintf(fp, "(EM_S390)\n"); break; + case EM_AARCH64: + fprintf(fp, "(EM_AARCH64)\n"); break; + default: + fprintf(fp, "(unknown)\n"); break; + } + + fprintf(fp, "\n header: %lx\n", (ulong)dd->header); + dh = dd->header; + fprintf(fp, " signature: \""); + for (i = 0; i < SIG_LEN; i++) + if (dh->signature[i]) + fprintf(fp, "%c", dh->signature[i]); + fprintf(fp, "\"\n"); + fprintf(fp, " header_version: %d\n", dh->header_version); + fprintf(fp, " utsname:\n"); + fprintf(fp, " sysname: %s\n", dh->utsname.sysname); + fprintf(fp, " nodename: %s\n", dh->utsname.nodename); + fprintf(fp, " release: %s\n", dh->utsname.release); + fprintf(fp, " version: %s\n", dh->utsname.version); + fprintf(fp, " machine: %s\n", dh->utsname.machine); + fprintf(fp, " domainname: %s\n", dh->utsname.domainname); + fprintf(fp, " timestamp:\n"); + fprintf(fp, " tv_sec: %lx\n", dh->timestamp.tv_sec); + fprintf(fp, " tv_usec: %lx\n", dh->timestamp.tv_usec); + fprintf(fp, " status: %x (", dh->status); + switch (dd->flags & (DISKDUMP_LOCAL|KDUMP_CMPRS_LOCAL)) + { + case DISKDUMP_LOCAL: + if (dh->status == DUMP_HEADER_COMPLETED) + fprintf(fp, "DUMP_HEADER_COMPLETED"); + else if (dh->status == DUMP_HEADER_INCOMPLETED) + fprintf(fp, "DUMP_HEADER_INCOMPLETED"); + else if (dh->status == DUMP_HEADER_COMPRESSED) + fprintf(fp, "DUMP_HEADER_COMPRESSED"); + break; + case KDUMP_CMPRS_LOCAL: + if (dh->status & DUMP_DH_COMPRESSED_ZLIB) + fprintf(fp, "DUMP_DH_COMPRESSED_ZLIB"); + if (dh->status & DUMP_DH_COMPRESSED_LZO) + fprintf(fp, "DUMP_DH_COMPRESSED_LZO"); + if (dh->status & DUMP_DH_COMPRESSED_SNAPPY) + fprintf(fp, "DUMP_DH_COMPRESSED_SNAPPY"); + break; + } + fprintf(fp, ")\n"); + fprintf(fp, " block_size: %d\n", dh->block_size); + fprintf(fp, " sub_hdr_size: %d\n", dh->sub_hdr_size); + fprintf(fp, " bitmap_blocks: %u\n", dh->bitmap_blocks); + fprintf(fp, " max_mapnr: %u\n", dh->max_mapnr); + fprintf(fp, " total_ram_blocks: %u\n", dh->total_ram_blocks); + fprintf(fp, " device_blocks: %u\n", dh->device_blocks); + fprintf(fp, " written_blocks: %u\n", dh->written_blocks); + fprintf(fp, " current_cpu: %u\n", dh->current_cpu); + fprintf(fp, " nr_cpus: %d\n", dh->nr_cpus); + tasks = (ulong *)&dh->tasks[0]; + fprintf(fp, " tasks[nr_cpus]: %lx\n", *tasks); + for (tasks++, i = 1; i < dh->nr_cpus; i++) { + fprintf(fp, " %lx\n", *tasks); + tasks++; + } + fprintf(fp, "\n"); + fprintf(fp, " sub_header: %lx ", (ulong)dd->sub_header); + if ((dsh = dd->sub_header)) { + fprintf(fp, "\n elf_regs: %lx\n", + (ulong)&dsh->elf_regs); + fprintf(fp, " dump_level: "); + if ((pc->flags & RUNTIME) && + ((dump_level = get_dump_level()) >= 0)) { + fprintf(fp, "%d (0x%x) %s", dump_level, dump_level, + dump_level ? "(" : ""); + +#define DUMP_EXCLUDE_CACHE 0x00000001 /* Exclude LRU & SwapCache pages*/ +#define DUMP_EXCLUDE_CLEAN 0x00000002 /* Exclude all-zero pages */ +#define DUMP_EXCLUDE_FREE 0x00000004 /* Exclude free pages */ +#define DUMP_EXCLUDE_ANON 0x00000008 /* Exclude Anon pages */ +#define DUMP_SAVE_PRIVATE 0x00000010 /* Save private pages */ + + others = 0; + if (dump_level & DUMP_EXCLUDE_CACHE) + fprintf(fp, "%sDUMP_EXCLUDE_CACHE", + others++ ? "|" : ""); + if (dump_level & DUMP_EXCLUDE_CLEAN) + fprintf(fp, "%sDUMP_EXCLUDE_CLEAN", + others++ ? "|" : ""); + if (dump_level & DUMP_EXCLUDE_FREE) + fprintf(fp, "%sDUMP_EXCLUDE_FREE", + others++ ? "|" : ""); + if (dump_level & DUMP_EXCLUDE_ANON) + fprintf(fp, "%sDUMP_EXCLUDE_ANON", + others++ ? "|" : ""); + if (dump_level & DUMP_SAVE_PRIVATE) + fprintf(fp, "%sDUMP_SAVE_PRIVATE", + others++ ? "|" : ""); + fprintf(fp, "%s\n\n", dump_level ? ")" : ""); + } else + fprintf(fp, "%s\n\n", pc->flags & RUNTIME ? + "(unknown)" : "(undetermined)"); + + } else + fprintf(fp, "(n/a)\n\n"); + + fprintf(fp, " sub_header_kdump: %lx ", (ulong)dd->sub_header_kdump); + if ((kdsh = dd->sub_header_kdump)) { + fprintf(fp, "\n phys_base: %lx\n", + (ulong)kdsh->phys_base); + fprintf(fp, " dump_level: "); + if ((dump_level = get_dump_level()) >= 0) { + fprintf(fp, "%d (0x%x) %s", dump_level, dump_level, + dump_level ? "(" : ""); + +#define DL_EXCLUDE_ZERO (0x001) /* Exclude Pages filled with Zeros */ +#define DL_EXCLUDE_CACHE (0x002) /* Exclude Cache Pages without Private Pages */ +#define DL_EXCLUDE_CACHE_PRI (0x004) /* Exclude Cache Pages with Private Pages */ +#define DL_EXCLUDE_USER_DATA (0x008) /* Exclude UserProcessData Pages */ +#define DL_EXCLUDE_FREE (0x010) /* Exclude Free Pages */ + + if (dump_level & DL_EXCLUDE_ZERO) + fprintf(fp, "%sDUMP_EXCLUDE_ZERO", + others++ ? "|" : ""); + if (dump_level & DL_EXCLUDE_CACHE) + fprintf(fp, "%sDUMP_EXCLUDE_CACHE", + others++ ? "|" : ""); + if (dump_level & DL_EXCLUDE_CACHE_PRI) + fprintf(fp, "%sDUMP_EXCLUDE_CACHE_PRI", + others++ ? "|" : ""); + if (dump_level & DL_EXCLUDE_USER_DATA) + fprintf(fp, "%sDUMP_EXCLUDE_USER_DATA", + others++ ? "|" : ""); + if (dump_level & DL_EXCLUDE_FREE) + fprintf(fp, "%sDUMP_EXCLUDE_FREE", + others++ ? "|" : ""); + others = 0; + + fprintf(fp, "%s\n", dump_level ? ")" : ""); + } else + fprintf(fp, "(unknown)\n"); + + if (dh->header_version >= 2) { + fprintf(fp, " split: %d\n", kdsh->split); + fprintf(fp, " start_pfn: "); + if (KDUMP_SPLIT()) + fprintf(fp, "%ld (0x%lx)\n", + kdsh->start_pfn, kdsh->start_pfn); + else + fprintf(fp, "(unused)\n"); + fprintf(fp, " end_pfn: "); + if (KDUMP_SPLIT()) + fprintf(fp, "%ld (0x%lx)\n", + kdsh->end_pfn, kdsh->end_pfn); + else + fprintf(fp, "(unused)\n"); + } + if (dh->header_version >= 3) { + fprintf(fp, " offset_vmcoreinfo: %llu (0x%llx)\n", + (ulonglong)dd->sub_header_kdump->offset_vmcoreinfo, + (ulonglong)dd->sub_header_kdump->offset_vmcoreinfo); + fprintf(fp, " size_vmcoreinfo: %lu (0x%lx)\n", + dd->sub_header_kdump->size_vmcoreinfo, + dd->sub_header_kdump->size_vmcoreinfo); + if (dd->sub_header_kdump->offset_vmcoreinfo && + dd->sub_header_kdump->size_vmcoreinfo) { + dump_vmcoreinfo(fp); + } + } + if (dh->header_version >= 4) { + fprintf(fp, " offset_note: %llu (0x%llx)\n", + (ulonglong)dd->sub_header_kdump->offset_note, + (ulonglong)dd->sub_header_kdump->offset_note); + fprintf(fp, " size_note: %lu (0x%lx)\n", + dd->sub_header_kdump->size_note, + dd->sub_header_kdump->size_note); + fprintf(fp, " num_prstatus_notes: %d\n", + dd->num_prstatus_notes); + fprintf(fp, " notes_buf: %lx\n", + (ulong)dd->notes_buf); + for (i = 0; i < dd->num_prstatus_notes; i++) { + fprintf(fp, " notes[%d]: %lx\n", + i, (ulong)dd->nt_prstatus_percpu[i]); + } + dump_nt_prstatus_offset(fp); + } + if (dh->header_version >= 5) { + fprintf(fp, " offset_eraseinfo: %llu (0x%llx)\n", + (ulonglong)dd->sub_header_kdump->offset_eraseinfo, + (ulonglong)dd->sub_header_kdump->offset_eraseinfo); + fprintf(fp, " size_eraseinfo: %lu (0x%lx)\n", + dd->sub_header_kdump->size_eraseinfo, + dd->sub_header_kdump->size_eraseinfo); + if (dd->sub_header_kdump->offset_eraseinfo && + dd->sub_header_kdump->size_eraseinfo) { + dump_eraseinfo(fp); + } + } + if (dh->header_version >= 6) { + fprintf(fp, " start_pfn_64: "); + if (KDUMP_SPLIT()) + fprintf(fp, "%lld (0x%llx)\n", + kdsh->start_pfn_64, kdsh->start_pfn_64); + else + fprintf(fp, "(unused)\n"); + fprintf(fp, " end_pfn_64: "); + if (KDUMP_SPLIT()) + fprintf(fp, "%lld (0x%llx)\n", + kdsh->end_pfn_64, kdsh->end_pfn_64); + else + fprintf(fp, "(unused)\n"); + + fprintf(fp, " max_mapnr_64: %llu (0x%llx)\n", + kdsh->max_mapnr_64, kdsh->max_mapnr_64); + } + fprintf(fp, "\n"); + } else + fprintf(fp, "(n/a)\n\n"); + + fprintf(fp, " data_offset: %lx\n", (ulong)dd->data_offset); + fprintf(fp, " block_size: %d\n", dd->block_size); + fprintf(fp, " block_shift: %d\n", dd->block_shift); + fprintf(fp, " bitmap: %lx\n", (ulong)dd->bitmap); + fprintf(fp, " bitmap_len: %lld\n", (ulonglong)dd->bitmap_len); + fprintf(fp, " max_mapnr: %lld (0x%llx)\n", dd->max_mapnr, dd->max_mapnr); + fprintf(fp, " dumpable_bitmap: %lx\n", (ulong)dd->dumpable_bitmap); + fprintf(fp, " byte: %d\n", dd->byte); + fprintf(fp, " bit: %d\n", dd->bit); + fprintf(fp, " compressed_page: %lx\n", (ulong)dd->compressed_page); + fprintf(fp, " curbufptr: %lx\n\n", (ulong)dd->curbufptr); + + for (i = 0; i < DISKDUMP_CACHED_PAGES; i++) { + fprintf(fp, "%spage_cache_hdr[%d]:\n", i < 10 ? " " : "", i); + fprintf(fp, " pg_flags: %x (", dd->page_cache_hdr[i].pg_flags); + others = 0; + if (dd->page_cache_hdr[i].pg_flags & PAGE_VALID) + fprintf(fp, "%sPAGE_VALID", others++ ? "|" : ""); + fprintf(fp, ")\n"); + fprintf(fp, " pg_addr: %llx\n", (ulonglong)dd->page_cache_hdr[i].pg_addr); + fprintf(fp, " pg_bufptr: %lx\n", (ulong)dd->page_cache_hdr[i].pg_bufptr); + fprintf(fp, " pg_hit_count: %ld\n", dd->page_cache_hdr[i].pg_hit_count); + } + + fprintf(fp, "\n page_cache_buf: %lx\n", (ulong)dd->page_cache_buf); + fprintf(fp, " evict_index: %d\n", dd->evict_index); + fprintf(fp, " evictions: %ld\n", dd->evictions); + fprintf(fp, " accesses: %ld\n", dd->accesses); + fprintf(fp, " cached_reads: %ld ", dd->cached_reads); + if (dd->accesses) + fprintf(fp, "(%ld%%)\n", + dd->cached_reads * 100 / dd->accesses); + else + fprintf(fp, "\n"); + fprintf(fp, " valid_pages: %lx\n", (ulong)dd->valid_pages); + + return 0; +} + +/* + * Wrapper of __diskdump_memory_dump() + */ +int +diskdump_memory_dump(FILE *fp) +{ + int i; + + if (KDUMP_SPLIT() && (dd_list != NULL)) + for (i = 0; i < num_dumpfiles; i++) { + dd = dd_list[i]; + __diskdump_memory_dump(fp); + fprintf(fp, "\n"); + } + else + __diskdump_memory_dump(fp); + + return 0; +} + + +/* + * Get the switch_stack address of the passed-in task. + */ +ulong +get_diskdump_switch_stack(ulong task) +{ + return 0; +} + +/* + * Versions of disk_dump that support it contain the "dump_level" symbol. + * Version 1 and later compressed kdump dumpfiles contain the dump level + * in an additional field of the sub_header_kdump structure. + */ +static int +get_dump_level(void) +{ + int dump_level; + + if (DISKDUMP_VALID()) { + if (symbol_exists("dump_level") && + readmem(symbol_value("dump_level"), KVADDR, &dump_level, + sizeof(dump_level), "dump_level", QUIET|RETURN_ON_ERROR)) + return dump_level; + } else if (KDUMP_CMPRS_VALID()) { + if (dd->header->header_version >= 1) + return dd->sub_header_kdump->dump_level; + } + + return -1; +} + +/* + * Used by the "sys" command to display [PARTIAL DUMP] + * after the dumpfile name. + */ +int +is_partial_diskdump(void) +{ + return (get_dump_level() > 0 ? TRUE : FALSE); +} + +/* + * Used by "sys" command to dump multiple split dumpfiles. + */ +void +show_split_dumpfiles(void) +{ + int i; + struct diskdump_data *ddp; + + for (i = 0; i < num_dumpfiles; i++) { + ddp = dd_list[i]; + fprintf(fp, "%s%s %s", + i ? " " : "", + ddp->filename, + is_partial_diskdump() ? "[PARTIAL DUMP]" : ""); + if ((i+1) < num_dumpfiles) + fprintf(fp, "\n"); + } +} + +void * +diskdump_get_prstatus_percpu(int cpu) +{ + if ((cpu < 0) || (cpu >= dd->num_prstatus_notes)) + return NULL; + + return dd->nt_prstatus_percpu[cpu]; +} + +/* + * Reads a string value from VMCOREINFO. + * + * Returns a string (that has to be freed by the caller) that contains the + * value for key or NULL if the key has not been found. + */ +static char * +vmcoreinfo_read_string(const char *key) +{ + char *buf, *value_string, *p1, *p2; + size_t value_length; + ulong size_vmcoreinfo; + off_t offset; + char keybuf[BUFSIZE]; + const off_t failed = (off_t)-1; + + buf = value_string = NULL; + size_vmcoreinfo = dd->sub_header_kdump->size_vmcoreinfo; + offset = dd->sub_header_kdump->offset_vmcoreinfo; + sprintf(keybuf, "%s=", key); + + if ((buf = malloc(size_vmcoreinfo+1)) == NULL) { + error(INFO, "compressed kdump: cannot malloc vmcoreinfo" + " buffer\n"); + goto err; + } + + if (FLAT_FORMAT()) { + if (!read_flattened_format(dd->dfd, offset, buf, size_vmcoreinfo)) { + error(INFO, "compressed kdump: cannot read vmcoreinfo data\n"); + goto err; + } + } else { + if (lseek(dd->dfd, offset, SEEK_SET) == failed) { + error(INFO, "compressed kdump: cannot lseek dump vmcoreinfo\n"); + goto err; + } + if (read(dd->dfd, buf, size_vmcoreinfo) < size_vmcoreinfo) { + error(INFO, "compressed kdump: cannot read vmcoreinfo data\n"); + goto err; + } + } + + buf[size_vmcoreinfo] = '\n'; + + if ((p1 = strstr(buf, keybuf))) { + p2 = p1 + strlen(keybuf); + p1 = strstr(p2, "\n"); + value_length = p1-p2; + value_string = calloc(value_length+1, sizeof(char)); + strncpy(value_string, p2, value_length); + value_string[value_length] = NULLCHAR; + } +err: + if (buf) + free(buf); + + return value_string; +} + +static void +diskdump_get_osrelease(void) +{ + char *string; + + if ((string = vmcoreinfo_read_string("OSRELEASE"))) { + fprintf(fp, "%s\n", string); + free(string); + } + else + pc->flags2 &= ~GET_OSRELEASE; +} + +void +diskdump_display_regs(int cpu, FILE *ofp) +{ + Elf32_Nhdr *note32; + Elf64_Nhdr *note64; + char *user_regs; + size_t len; + + if (!diskdump_get_prstatus_percpu(cpu)) { + error(INFO, "registers not collected for cpu %d\n", cpu); + return; + } + + if (machine_type("X86_64")) { + note64 = dd->nt_prstatus_percpu[cpu]; + len = sizeof(Elf64_Nhdr); + len = roundup(len + note64->n_namesz, 4); + len = roundup(len + note64->n_descsz, 4); + user_regs = (char *)note64 + len - SIZE(user_regs_struct) - sizeof(long); + fprintf(ofp, + " RIP: %016llx RSP: %016llx RFLAGS: %08llx\n" + " RAX: %016llx RBX: %016llx RCX: %016llx\n" + " RDX: %016llx RSI: %016llx RDI: %016llx\n" + " RBP: %016llx R8: %016llx R9: %016llx\n" + " R10: %016llx R11: %016llx R12: %016llx\n" + " R13: %016llx R14: %016llx R15: %016llx\n" + " CS: %04x SS: %04x\n", + ULONGLONG(user_regs + OFFSET(user_regs_struct_rip)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_rsp)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_eflags)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_rax)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_rbx)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_rcx)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_rdx)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_rsi)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_rdi)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_rbp)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_r8)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_r9)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_r10)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_r11)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_r12)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_r13)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_r14)), + ULONGLONG(user_regs + OFFSET(user_regs_struct_r15)), + USHORT(user_regs + OFFSET(user_regs_struct_cs)), + USHORT(user_regs + OFFSET(user_regs_struct_ss)) + ); + } + + if (machine_type("ARM64")) { + note64 = dd->nt_prstatus_percpu[cpu]; + len = sizeof(Elf64_Nhdr); + len = roundup(len + note64->n_namesz, 4); + len = roundup(len + note64->n_descsz, 4); +// user_regs = (char *)note64 + len - SIZE(user_regs_struct) - sizeof(long); + fprintf(ofp, "diskdump_display_regs: ARM64 register dump TBD\n"); + } + + if (machine_type("X86")) { + note32 = dd->nt_prstatus_percpu[cpu]; + len = sizeof(Elf32_Nhdr); + len = roundup(len + note32->n_namesz, 4); + len = roundup(len + note32->n_descsz, 4); + user_regs = (char *)note32 + len - SIZE(user_regs_struct) - sizeof(int); + fprintf(ofp, + " EAX: %08x EBX: %08x ECX: %08x EDX: %08x\n" + " ESP: %08x EIP: %08x ESI: %08x EDI: %08x\n" + " CS: %04x DS: %04x ES: %04x FS: %04x\n" + " GS: %04x SS: %04x\n" + " EBP: %08x EFLAGS: %08x\n", + UINT(user_regs + OFFSET(user_regs_struct_eax)), + UINT(user_regs + OFFSET(user_regs_struct_ebx)), + UINT(user_regs + OFFSET(user_regs_struct_ecx)), + UINT(user_regs + OFFSET(user_regs_struct_edx)), + UINT(user_regs + OFFSET(user_regs_struct_esp)), + UINT(user_regs + OFFSET(user_regs_struct_eip)), + UINT(user_regs + OFFSET(user_regs_struct_esi)), + UINT(user_regs + OFFSET(user_regs_struct_edi)), + USHORT(user_regs + OFFSET(user_regs_struct_cs)), + USHORT(user_regs + OFFSET(user_regs_struct_ds)), + USHORT(user_regs + OFFSET(user_regs_struct_es)), + USHORT(user_regs + OFFSET(user_regs_struct_fs)), + USHORT(user_regs + OFFSET(user_regs_struct_gs)), + USHORT(user_regs + OFFSET(user_regs_struct_ss)), + UINT(user_regs + OFFSET(user_regs_struct_ebp)), + UINT(user_regs + OFFSET(user_regs_struct_eflags)) + ); + } +} + +void +dump_registers_for_compressed_kdump(void) +{ + int c; + + if (!KDUMP_CMPRS_VALID() || (dd->header->header_version < 4) || + !(machine_type("X86") || machine_type("X86_64") || machine_type("ARM64"))) + error(FATAL, "-r option not supported for this dumpfile\n"); + + for (c = 0; c < kt->cpus; c++) { + fprintf(fp, "%sCPU %d:\n", c ? "\n" : "", c); + diskdump_display_regs(c, fp); + } +} + + diff --git a/diskdump.h b/diskdump.h new file mode 100644 index 00000000..88c5be9a --- /dev/null +++ b/diskdump.h @@ -0,0 +1,99 @@ +/* + * diskdump.h + * + * Copyright (C) 2004, 2005, 2006 David Anderson + * Copyright (C) 2004, 2005, 2006 Red Hat, Inc. All rights reserved. + * Copyright (C) 2005 FUJITSU LIMITED + * Copyright (C) 2005 NEC Corporation + * + * 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. + */ + +#include + +#define divideup(x, y) (((x) + ((y) - 1)) / (y)) +#define round(x, y) (((x) / (y)) * (y)) + +#define DUMP_PARTITION_SIGNATURE "diskdump" +#define SIG_LEN (sizeof(DUMP_PARTITION_SIGNATURE) - 1) +#define DISK_DUMP_SIGNATURE "DISKDUMP" +#define KDUMP_SIGNATURE "KDUMP " + +#define DUMP_HEADER_COMPLETED 0 +#define DUMP_HEADER_INCOMPLETED 1 +#define DUMP_HEADER_COMPRESSED 8 + +struct disk_dump_header { + char signature[SIG_LEN]; /* = "DISKDUMP" */ + int header_version; /* Dump header version */ + struct new_utsname utsname; /* copy of system_utsname */ + struct timeval timestamp; /* Time stamp */ + unsigned int status; /* Above flags */ + int block_size; /* Size of a block in byte */ + int sub_hdr_size; /* Size of arch dependent + header in blocks */ + unsigned int bitmap_blocks; /* Size of Memory bitmap in + block */ + unsigned int max_mapnr; /* = max_mapnr, OBSOLETE! + 32bit only, full 64bit + in sub header. */ + unsigned int total_ram_blocks;/* Number of blocks should be + written */ + unsigned int device_blocks; /* Number of total blocks in + * the dump device */ + unsigned int written_blocks; /* Number of written blocks */ + unsigned int current_cpu; /* CPU# which handles dump */ + int nr_cpus; /* Number of CPUs */ + struct task_struct *tasks[0]; +}; + +struct disk_dump_sub_header { + long elf_regs; +}; + +struct kdump_sub_header { + unsigned long phys_base; + int dump_level; /* header_version 1 and later */ + int split; /* header_version 2 and later */ + unsigned long start_pfn; /* header_version 2 and later, + OBSOLETE! 32bit only, full 64bit + in start_pfn_64. */ + unsigned long end_pfn; /* header_version 2 and later, + OBSOLETE! 32bit only, full 64bit + in end_pfn_64. */ + off_t offset_vmcoreinfo; /* header_version 3 and later */ + unsigned long size_vmcoreinfo; /* header_version 3 and later */ + off_t offset_note; /* header_version 4 and later */ + unsigned long size_note; /* header_version 4 and later */ + off_t offset_eraseinfo; /* header_version 5 and later */ + unsigned long size_eraseinfo; /* header_version 5 and later */ + unsigned long long start_pfn_64; /* header_version 6 and later */ + unsigned long long end_pfn_64; /* header_version 6 and later */ + unsigned long long max_mapnr_64; /* header_version 6 and later */ +}; + +/* page flags */ +#define DUMP_DH_COMPRESSED_ZLIB 0x1 /* page is compressed with zlib */ +#define DUMP_DH_COMPRESSED_LZO 0x2 /* page is compressed with lzo */ +#define DUMP_DH_COMPRESSED_SNAPPY 0x4 /* page is compressed with snappy */ + +/* descriptor of each page for vmcore */ +typedef struct page_desc { + off_t offset; /* the offset of the page data*/ + unsigned int size; /* the size of this dump page */ + unsigned int flags; /* flags */ + unsigned long long page_flags; /* page flags */ +} page_desc_t; + +#define DISKDUMP_CACHED_PAGES (16) +#define PAGE_VALID (0x1) /* flags */ +#define DISKDUMP_VALID_PAGE(flags) ((flags) & PAGE_VALID) + diff --git a/extensions.c b/extensions.c new file mode 100644 index 00000000..8c4a17ba --- /dev/null +++ b/extensions.c @@ -0,0 +1,559 @@ +/* extensions.c - core analysis suite + * + * Copyright (C) 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2013 David Anderson + * Copyright (C) 2002-2013 Red Hat, Inc. 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. + */ + +#include "defs.h" +#include + +static int in_extensions_library(char *, char *); +static char *get_extensions_directory(char *); + +#define DUMP_EXTENSIONS (0) +#define LOAD_EXTENSION (1) +#define UNLOAD_EXTENSION (2) + +/* + * Load, unload, or list the extension libaries. + */ +void +cmd_extend(void) +{ + int c; + int flag; + + flag = DUMP_EXTENSIONS; + + while ((c = getopt(argcnt, args, "lu")) != EOF) { + switch(c) + { + case 'l': + if (flag & UNLOAD_EXTENSION) { + error(INFO, + "-l and -u are mutually exclusive\n"); + argerrs++; + } else + flag |= LOAD_EXTENSION; + break; + + case 'u': + if (flag & LOAD_EXTENSION) { + error(INFO, + "-u and -l are mutually exclusive\n"); + argerrs++; + } else + flag |= UNLOAD_EXTENSION; + break; + + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + switch (flag) + { + case DUMP_EXTENSIONS: + if (!args[optind]) { + dump_extension_table(!VERBOSE); + return; + } + /* FALLTHROUGH */ + + case LOAD_EXTENSION: + if (!args[optind]) { + error(INFO, + "-l requires one or more extension library arguments\n"); + cmd_usage(pc->curcmd, SYNOPSIS); + break; + } + + while (args[optind]) { + load_extension(args[optind]); + optind++; + } + break; + + case UNLOAD_EXTENSION: + if (!args[optind]) { + unload_extension(NULL); + break; + } + + while (args[optind]) { + unload_extension(args[optind]); + optind++; + } + break; + } +} + +/* + * List all extension libaries and their commands in either the extend + * command format or for "help -e" (verbose). + */ +void +dump_extension_table(int verbose) +{ + int i; + struct extension_table *ext; + struct command_table_entry *cp; + char buf[BUFSIZE]; + int longest, others; + + if (!extension_table) + return; + + if (verbose) { + for (ext = extension_table; ext; ext = ext->next) { + fprintf(fp, " filename: %s\n", ext->filename); + fprintf(fp, " handle: %lx\n", (ulong)ext->handle); + + + fprintf(fp, " flags: %lx (", ext->flags); + others = 0; + if (ext->flags & REGISTERED) + fprintf(fp, "%sREGISTERED", others++ ? + "|" : ""); + fprintf(fp, ")\n"); + fprintf(fp, " next: %lx\n", (ulong)ext->next); + fprintf(fp, " prev: %lx\n", (ulong)ext->prev); + + for (i = 0, cp = ext->command_table; cp->name; cp++, i++) { + fprintf(fp, "command_table[%d]: %lx\n", i, (ulong)cp); + fprintf(fp, " name: %s\n", cp->name); + fprintf(fp, " func: %lx\n", (ulong)cp->func); + fprintf(fp, " help_data: %lx\n", (ulong)cp->help_data); + fprintf(fp, " flags: %lx (", cp->flags); + others = 0; + if (cp->flags & CLEANUP) + fprintf(fp, "%sCLEANUP", others++ ? "|" : ""); + if (cp->flags & REFRESH_TASK_TABLE) + fprintf(fp, "%sREFRESH_TASK_TABLE", others++ ? "|" : ""); + if (cp->flags & HIDDEN_COMMAND) + fprintf(fp, "%sHIDDEN_COMMAND", others++ ? "|" : ""); + fprintf(fp, ")\n"); + } + + if (ext->next) + fprintf(fp, "\n"); + } + return; + } + + + /* + * Print them out in the order they were loaded. + */ + for (longest = 0, ext = extension_table; ext; ext = ext->next) { + if (strlen(ext->filename) > longest) + longest = strlen(ext->filename); + } + + fprintf(fp, "%s COMMANDS\n", + mkstring(buf, longest, LJUST, "SHARED OBJECT")); + longest = MAX(longest, strlen("SHARED OBJECT")); + + for (ext = extension_table; ext; ext = ext->next) + if (ext->next == NULL) + break; + + do { + fprintf(fp, "%s ", + mkstring(buf, longest, LJUST, ext->filename)); + for (cp = ext->command_table; cp->name; cp++) + fprintf(fp, "%s ", cp->name); + fprintf(fp, "\n"); + } while ((ext = ext->prev)); +} + + +/* + * Load an extension library. + */ +void +load_extension(char *lib) +{ + struct extension_table *ext, *curext; + char buf[BUFSIZE]; + size_t size; + char *env; + int env_len; + + if ((env = getenv("CRASH_EXTENSIONS"))) + env_len = strlen(env)+1; + else + env_len = 0; + + size = sizeof(struct extension_table) + strlen(lib) + + MAX(env_len, strlen("/usr/lib64/crash/extensions/")) + 1; + + if ((ext = (struct extension_table *)malloc(size)) == NULL) + error(FATAL, "cannot malloc extension_table space."); + + BZERO(ext, size); + + ext->filename = (char *)((ulong)ext + sizeof(struct extension_table)); + + /* + * If the library is not specified by an absolute pathname, dlopen() + * does not look in the current directory, so modify the filename. + * If it's not in the current directory, check the extensions library + * directory. + */ + if ((*lib != '.') && (*lib != '/')) { + if (file_exists(lib, NULL)) + sprintf(ext->filename, "./%s", lib); + else if (in_extensions_library(lib, buf)) + strcpy(ext->filename, buf); + else { + error(INFO, "%s: %s\n", lib, strerror(ENXIO)); + free(ext); + return; + } + } else + strcpy(ext->filename, lib); + + if (!is_shared_object(ext->filename)) { + error(INFO, "%s: not an ELF format object file\n", + ext->filename); + free(ext); + return; + } + + for (curext = extension_table; curext; curext = curext->next) { + if (same_file(curext->filename, ext->filename)) { + fprintf(fp, "%s: shared object already loaded\n", + ext->filename); + free(ext); + return; + } + } + + /* + * register_extension() will be called by the shared object's + * _init() function before dlopen() returns below. + */ + pc->curext = ext; + ext->handle = dlopen(ext->filename, RTLD_NOW|RTLD_GLOBAL); + + if (!ext->handle) { + strcpy(buf, dlerror()); + error(INFO, "%s\n", buf); + if (strstr(buf, "undefined symbol: register_extension")) { + error(INFO, "%s may be statically linked: ", + pc->program_name); + fprintf(fp, "recompile without the -static flag\n"); + } + free(ext); + return; + } + + if (!(ext->flags & REGISTERED)) { + dlclose(ext->handle); + if (ext->flags & (DUPLICATE_COMMAND_NAME | NO_MINIMAL_COMMANDS)) + error(INFO, + "%s: shared object unloaded\n", ext->filename); + else + error(INFO, + "%s: no commands registered: shared object unloaded\n", + ext->filename); + free(ext); + return; + } + + fprintf(fp, "%s: shared object loaded\n", ext->filename); + + /* + * Put new libraries at the head of the list. + */ + if (extension_table) { + extension_table->prev = ext; + ext->next = extension_table; + } + extension_table = ext; + + help_init(); +} + +/* + * Check the extensions library directories. + */ +static int +in_extensions_library(char *lib, char *buf) +{ + char *env; + + if ((env = getenv("CRASH_EXTENSIONS"))) { + sprintf(buf, "%s%s%s", env, + LASTCHAR(env) == '/' ? "" : "/", + lib); + if (file_exists(buf, NULL)) + return TRUE; + } + + if (BITS64()) { + sprintf(buf, "/usr/lib64/crash/extensions/%s", lib); + if (file_exists(buf, NULL)) + return TRUE; + } + + sprintf(buf, "/usr/lib/crash/extensions/%s", lib); + if (file_exists(buf, NULL)) + return TRUE; + + sprintf(buf, "./extensions/%s", lib); + if (file_exists(buf, NULL)) + return TRUE; + + return FALSE; +} + +/* + * Look for an extensions directory using the proper order. + */ +static char * +get_extensions_directory(char *dirbuf) +{ + char *env; + + if ((env = getenv("CRASH_EXTENSIONS"))) { + if (is_directory(env)) { + strcpy(dirbuf, env); + return dirbuf; + } + } + + if (BITS64()) { + sprintf(dirbuf, "/usr/lib64/crash/extensions"); + if (is_directory(dirbuf)) + return dirbuf; + } + + sprintf(dirbuf, "/usr/lib/crash/extensions"); + if (is_directory(dirbuf)) + return dirbuf; + + sprintf(dirbuf, "./extensions"); + if (is_directory(dirbuf)) + return dirbuf; + + return NULL; +} + + +void +preload_extensions(void) +{ + DIR *dirp; + struct dirent *dp; + char dirbuf[BUFSIZE]; + char filename[BUFSIZE]; + int found; + + if (!get_extensions_directory(dirbuf)) + return; + + dirp = opendir(dirbuf); + if (!dirp) { + error(INFO, "%s: %s\n", dirbuf, strerror(errno)); + return; + } + + pc->curcmd = pc->program_name; + + for (found = 0, dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { + sprintf(filename, "%s%s%s", dirbuf, + LASTCHAR(dirbuf) == '/' ? "" : "/", + dp->d_name); + + if (!is_shared_object(filename)) + continue; + + found++; + + load_extension(dp->d_name); + } + + closedir(dirp); + + if (found) + fprintf(fp, "\n"); + else + error(NOTE, + "%s: no extension modules found in directory\n\n", + dirbuf); +} + +/* + * Unload all, or as specified, extension libraries. + */ +void +unload_extension(char *lib) +{ + struct extension_table *ext; + int found; + char buf[BUFSIZE]; + + if (!lib) { + while (extension_table) { + ext = extension_table; + if (dlclose(ext->handle)) + error(FATAL, + "dlclose: %s: shared object not open\n", + ext->filename); + + fprintf(fp, "%s: shared object unloaded\n", + ext->filename); + + extension_table = ext->next; + free(ext); + } + + help_init(); + return; + } + + if ((*lib != '.') && (*lib != '/')) { + if (!file_exists(lib, NULL) && + in_extensions_library(lib, buf)) + lib = buf; + } + + if (!file_exists(lib, NULL)) { + error(INFO, "%s: %s\n", lib, strerror(ENXIO)); + return; + } + + for (ext = extension_table, found = FALSE; ext; ext = ext->next) { + if (same_file(lib, ext->filename)) { + found = TRUE; + if (dlclose(ext->handle)) + error(INFO, + "dlclose: %s: shared object not open\n", + ext->filename); + else { + fprintf(fp, "%s: shared object unloaded\n", + ext->filename); + + if (extension_table == ext) { /* first */ + extension_table = ext->next; + if (ext->next) + ext->next->prev = NULL; + } else if (ext->next == NULL) /* last */ + ext->prev->next = NULL; + else { /* middle */ + ext->prev->next = ext->next; + ext->next->prev = ext->prev; + } + + free(ext); + help_init(); + break; + } + } + else if (STREQ(basename(lib), basename(ext->filename))) { + error(INFO, "%s and %s are different object files\n", + lib, ext->filename); + found = TRUE; + } + } + + if (!found) + error(INFO, "%s: not loaded\n", lib); +} + +/* + * Register the command_table as long as there are no command namespace + * clashes with the currently-existing command set. Also delete any aliases + * that clash, giving the registered command name priority. + * + * This function is called from the shared object's _init() function + * before the dlopen() call returns back to load_extension() above. + * The mark of approval for load_extension() is the setting of the + * REGISTERED bit in the "current" extension_table structure flags. + */ +void +register_extension(struct command_table_entry *command_table) +{ + struct command_table_entry *cp; + + pc->curext->flags |= NO_MINIMAL_COMMANDS; + + for (cp = command_table; cp->name; cp++) { + if (get_command_table_entry(cp->name)) { + error(INFO, + "%s: \"%s\" is a duplicate of a currently-existing command\n", + pc->curext->filename, cp->name); + pc->curext->flags |= DUPLICATE_COMMAND_NAME; + return; + } + if (cp->flags & MINIMAL) + pc->curext->flags &= ~NO_MINIMAL_COMMANDS; + } + + if ((pc->flags & MINIMAL_MODE) && (pc->curext->flags & NO_MINIMAL_COMMANDS)) { + error(INFO, + "%s: does not contain any commands which support minimal mode\n", + pc->curext->filename); + return; + } + + if (pc->flags & MINIMAL_MODE) { + for (cp = command_table; cp->name; cp++) { + if (!(cp->flags & MINIMAL)) { + error(WARNING, + "%s: command \"%s\" does not support minimal mode\n", + pc->curext->filename, cp->name); + } + } + } + + for (cp = command_table; cp->name; cp++) { + if (is_alias(cp->name)) { + error(INFO, + "alias \"%s\" deleted: name clash with extension command\n", + cp->name); + deallocate_alias(cp->name); + } + } + + pc->curext->command_table = command_table; + pc->curext->flags |= REGISTERED; /* Mark of approval */ +} + +/* + * Hooks for sial. + */ +unsigned long +get_curtask(void) +{ + return CURRENT_TASK(); +} + +char * +crash_global_cmd(void) +{ + return pc->curcmd; +} + +struct command_table_entry * +crash_cmd_table(void) +{ + return pc->cmd_table; +} diff --git a/extensions/Makefile b/extensions/Makefile new file mode 100644 index 00000000..1e428059 --- /dev/null +++ b/extensions/Makefile @@ -0,0 +1,54 @@ +# +# Makefile for building crash shared object extensions +# +# Copyright (C) 2005, 2007, 2009, 2011, 2013 David Anderson +# Copyright (C) 2005, 2007, 2009, 2011, 2013 Red Hat, Inc. 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. +# +# To build the extension shared objects in this directory, run +# "make extensions" from the top-level directory. +# +# To add a new extension object, simply copy your module's .c file +# to this directory, and it will be built automatically using +# the "standard" compile line. If that compile line does not +# suffice, create a .mk file with the same prefix as the .c file, +# and that makefile will be invoked. +# + +CONTRIB_SO := $(patsubst %.c,%.so,$(wildcard *.c)) + +all: link_defs $(CONTRIB_SO) + +link_defs: + @rm -f defs.h + @ln ../defs.h + +$(CONTRIB_SO): %.so: %.c defs.h + @if [ -f $*.mk ]; then \ + make -f $*.mk; \ + else \ + grep '((constructor))' $*.c > .constructor; \ + if [ -s .constructor ]; then \ + echo "gcc -Wall -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS)"; \ + gcc -Wall -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS); \ + fi; \ + if [ ! -s .constructor ]; then \ + echo "gcc -Wall -nostartfiles -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS)"; \ + gcc -Wall -nostartfiles -shared -rdynamic -o $@ $*.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS); \ + fi; \ + fi + +clean: + rm -f $(CONTRIB_SO) + @for MAKEFILE in `grep -sl "^clean:" *.mk`; \ + do make --no-print-directory -f $$MAKEFILE clean; \ + done diff --git a/extensions/dminfo.c b/extensions/dminfo.c new file mode 100644 index 00000000..8de3ba56 --- /dev/null +++ b/extensions/dminfo.c @@ -0,0 +1,1533 @@ +/* dminfo.c - crash extension module for device-mapper analysis + * + * Copyright (C) 2005 NEC Corporation + * Copyright (C) 2005 Red Hat, Inc. 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. + */ + +#include "defs.h" /* From the crash source top-level directory */ + +void dminfo_init(void); +void dminfo_fini(void); + +/* + * Indices of size-offset array (Used by GET_xxx macros) + * + * DM__ + */ +enum { + DM_hash_cell_name_list = 0, + DM_hash_cell_name, + DM_hash_cell_md, + + DM_mapped_device_disk, + DM_mapped_device_map, + + DM_gendisk_major, + DM_gendisk_first_minor, + DM_gendisk_disk_name, + + DM_dm_table_num_targets, + DM_dm_table_targets, + DM_dm_table_devices, + + DM_dm_target_type, + DM_dm_target_begin, + DM_dm_target_len, + DM_dm_target_private, + + DM_dm_dev_count, + DM_dm_dev_bdev, + DM_dm_dev_name, + + DM_dm_io_md, + DM_dm_io_bio, + + DM_target_type_name, + + DM_target_io_io, + + DM_block_device_bd_disk, + + DM_bio_bi_private, + + DM_bio_list_head, + + DM_linear_c_dev, + DM_linear_c_start, + + DM_multipath_hw_handler, + DM_multipath_nr_priority_groups, + DM_multipath_priority_groups, + DM_multipath_nr_valid_paths, + DM_multipath_current_pg, + DM_multipath_queue_if_no_path, + DM_multipath_queue_size, + + DM_hw_handler_type, + DM_hw_handler_type_name, + + DM_priority_group_ps, + DM_priority_group_pg_num, + DM_priority_group_bypassed, + DM_priority_group_nr_pgpaths, + DM_priority_group_pgpaths, + + DM_path_selector_type, + DM_path_selector_type_name, + + DM_pgpath_fail_count, + DM_pgpath_path, + + DM_path_dev, + DM_path_is_active, + + DM_mirror_set_rh, + DM_mirror_set_reads, + DM_mirror_set_writes, + DM_mirror_set_in_sync, + DM_mirror_set_nr_mirrors, + DM_mirror_set_mirror, + + DM_region_hash_log, + DM_region_hash_quiesced_regions, + DM_region_hash_recovered_regions, + + DM_dirty_log_type, + DM_dirty_log_type_name, + + DM_mirror_error_count, + DM_mirror_dev, + DM_mirror_offset, + + DM_crypt_config_dev, + DM_crypt_config_iv_mode, + DM_crypt_config_tfm, + DM_crypt_config_key_size, + DM_crypt_config_key, + + DM_crypto_tfm_crt_u, + DM_crypto_tfm___crt_alg, + + DM_crypto_alg_cra_name, + + DM_cipher_tfm_cit_mode, + + DM_stripe_c_stripes, + DM_stripe_c_chunk_mask, + DM_stripe_c_stripe, + + DM_stripe_dev, + + DM_dm_snapshot_origin, + DM_dm_snapshot_cow, + DM_dm_snapshot_chunk_size, + DM_dm_snapshot_valid, + DM_dm_snapshot_type, + + NR_DMINFO_MEMBER_TABLE_ENTRY +}; + +/* Size-offset array for structure's member */ +static struct dminfo_member_entry { + unsigned long offset; + unsigned long size; +} mbr_ary[NR_DMINFO_MEMBER_TABLE_ENTRY]; + +/* + * Macros to retrieve data of given structure's member + * + * Macros except for the MSG assume 'struct s' is at 'addr' + */ +#define MSG(msg, s, m) msg ": " s "." m + +/* Initialize the size-offset array */ +#define INIT_MBR_TABLE(s, m) \ + do { \ + if (!mbr_ary[DM_##s##_##m].size) { \ + mbr_ary[DM_##s##_##m].offset = MEMBER_OFFSET("struct " #s, #m); \ + mbr_ary[DM_##s##_##m].size = MEMBER_SIZE("struct " #s, #m); \ + } \ + } while (0) + +/* + * Store the data of member m in ret. + * Initialize the size-offset array for the member m if needed. + */ +#define GET_VALUE(addr, s, m, ret) \ + do { \ + INIT_MBR_TABLE(s, m); \ + if (sizeof(ret) < mbr_ary[DM_##s##_##m].size) \ + fprintf(fp, "%s\n", \ + MSG("ERROR: GET_VALUE size_check", #s, #m)); \ + readmem(addr + mbr_ary[DM_##s##_##m].offset, KVADDR, &ret, \ + mbr_ary[DM_##s##_##m].size, MSG("GET_VALUE", #s, #m), \ + FAULT_ON_ERROR);\ + } while (0) + +/* + * Store the address of member m in ret. + * Initialize the size-offset array for the member m if needed. + */ +#define GET_ADDR(addr, s, m, ret) \ + do { \ + INIT_MBR_TABLE(s, m); \ + ret = addr + mbr_ary[DM_##s##_##m].offset; \ + } while (0) + +/* + * Store the string data of member m in ret. + * Initialize the size-offset array for the member m if needed. + */ +#define GET_STR(addr, s, m, ret, len) \ + do { \ + INIT_MBR_TABLE(s, m); \ + if (!read_string(addr + mbr_ary[DM_##s##_##m].offset, ret, len - 1)) \ + fprintf(fp, "%s\n", MSG("ERROR: GET_STR", #s, #m)); \ + } while (0) + +/* + * Store the string data pointed by member m in ret. + * Initialize the size-offset array for the member m if needed. + */ +#define GET_PTR_STR(addr, s, m, ret, len) \ + do { \ + unsigned long tmp; \ + INIT_MBR_TABLE(s, m); \ + readmem(addr + mbr_ary[DM_##s##_##m].offset, KVADDR, &tmp, \ + mbr_ary[DM_##s##_##m].size, MSG("GET_PTR_STR", #s, #m),\ + FAULT_ON_ERROR);\ + if (!read_string(tmp, ret, len - 1)) \ + fprintf(fp, "%s\n", MSG("ERROR: GET_PTR_STR", #s, #m));\ + } while (0) + +/* + * Utility function/macro to walk the list + */ +static unsigned long +get_next_from_list_head(unsigned long addr) +{ + unsigned long ret; + + readmem(addr + OFFSET(list_head_next), KVADDR, &ret, sizeof(void *), + MSG("get_next_from_list_head", "list_head", "next"), + FAULT_ON_ERROR); + + return ret; +} + +#define list_for_each(next, head, last) \ + for (next = get_next_from_list_head(head), last = 0UL; \ + next && next != head && next != last; \ + last = next, next = get_next_from_list_head(next)) + +/* + * device-mapper target analyzer + * + * device-mapper has various target driver: linear, mirror, multipath, etc. + * Information specific to target is stored in its own way. + * Target-specific analyzer is provided for each target driver for this reason. + */ +static struct dminfo_target_analyzer { + struct dminfo_target_analyzer *next; + char *target_name; + int (*ready) (void); /* returns true if analyzer is available */ + void (*show_table) (unsigned long); /* display table info */ + void (*show_status) (unsigned long); /* display status info */ + void (*show_queue) (unsigned long); /* display queued I/O info */ +} analyzers_head; + +static void +dminfo_register_target_analyzer(struct dminfo_target_analyzer *ta) +{ + ta->next = analyzers_head.next; + analyzers_head.next = ta; +} + +static struct +dminfo_target_analyzer *find_target_analyzer(char *target_type) +{ + struct dminfo_target_analyzer *ta; + + for (ta = analyzers_head.next; ta; ta = ta->next) + if (!strcmp(ta->target_name, target_type)) + return ta; + + return NULL; +} + +/* + * zero target + */ +static int +zero_ready(void) +{ + return 1; +} + +static void +zero_show_table(unsigned long target) +{ + unsigned long long start, len; + + /* Get target information */ + GET_VALUE(target, dm_target, begin, start); + GET_VALUE(target, dm_target, len, len); + + fprintf(fp, " begin:%llu len:%llu", start, len); +} + +static void +zero_show_status(unsigned long target) +{ + /* zero target has no status */ + fprintf(fp, " No status info"); +} + +static void +zero_show_queue(unsigned long target) +{ + /* zero target has no queue */ + fprintf(fp, " No queue info"); +} + +static struct dminfo_target_analyzer zero_analyzer = { + .target_name = "zero", + .ready = zero_ready, + .show_table = zero_show_table, + .show_status = zero_show_status, + .show_queue = zero_show_queue +}; + +/* + * error target + */ +static int +error_ready(void) +{ + return 1; +} + +static void +error_show_table(unsigned long target) +{ + unsigned long long start, len; + + /* Get target information */ + GET_VALUE(target, dm_target, begin, start); + GET_VALUE(target, dm_target, len, len); + + fprintf(fp, " begin:%llu len:%llu", start, len); +} + +static void +error_show_status(unsigned long target) +{ + /* error target has no status */ + fprintf(fp, " No status info"); +} + +static void +error_show_queue(unsigned long target) +{ + /* error target has no queue */ + fprintf(fp, " No queue info"); +} + +static struct dminfo_target_analyzer error_analyzer = { + .target_name = "error", + .ready = error_ready, + .show_table = error_show_table, + .show_status = error_show_status, + .show_queue = error_show_queue +}; + +/* + * linear target + */ +static int +linear_ready(void) +{ + static int debuginfo = 0; + + if (debuginfo) + return 1; + + if (STRUCT_EXISTS("struct linear_c")) { + debuginfo = 1; + return 1; + } else + fprintf(fp, "No such struct info: linear_c"); + + return 0; +} + +static void +linear_show_table(unsigned long target) +{ + unsigned long lc, dm_dev; + unsigned long long start, len, offset; + char devt[BUFSIZE]; + + /* Get target information */ + GET_VALUE(target, dm_target, begin, start); + GET_VALUE(target, dm_target, len, len); + GET_VALUE(target, dm_target, private, lc); + GET_VALUE(lc, linear_c, dev, dm_dev); + GET_STR(dm_dev, dm_dev, name, devt, BUFSIZE); + GET_VALUE(lc, linear_c, start, offset); + + fprintf(fp, " begin:%llu len:%llu dev:%s offset:%llu", + start, len, devt, offset); +} + +static void +linear_show_status(unsigned long target) +{ + /* linear target has no status */ + fprintf(fp, " No status info"); +} + +static void +linear_show_queue(unsigned long target) +{ + /* linear target has no I/O queue */ + fprintf(fp, " No queue info"); +} + +static struct dminfo_target_analyzer linear_analyzer = { + .target_name = "linear", + .ready = linear_ready, + .show_table = linear_show_table, + .show_status = linear_show_status, + .show_queue = linear_show_queue +}; + +/* + * mirror target + */ +static int +mirror_ready(void) +{ + static int debuginfo = 0; + + if (debuginfo) + return 1; + + if (STRUCT_EXISTS("struct mirror_set")) { + debuginfo = 1; + return 1; + } else + fprintf(fp, "No such struct info: mirror_set"); + + return 0; +} + +static void +mirror_show_table(unsigned long target) +{ + unsigned int i, nr_mir; + unsigned long ms, rh, log, log_type, mir_size, mir_head, mir, dm_dev; + unsigned long long offset; + char buf[BUFSIZE]; + + /* Get the address of struct mirror_set */ + GET_VALUE(target, dm_target, private, ms); + + /* Get the log-type name of the mirror_set */ + GET_ADDR(ms, mirror_set, rh, rh); + GET_VALUE(rh, region_hash, log, log); + GET_VALUE(log, dirty_log, type, log_type); + GET_PTR_STR(log_type, dirty_log_type, name, buf, BUFSIZE); + fprintf(fp, " log:%s", buf); + + /* + * Display information for each mirror disks. + * + * mir_head = mirror_set.mirror. + * This is the head of struct mirror array. + */ + fprintf(fp, " dev:"); + mir_size = STRUCT_SIZE("struct mirror"); + GET_ADDR(ms, mirror_set, mirror, mir_head); + GET_VALUE(ms, mirror_set, nr_mirrors, nr_mir); + for (i = 0; i < nr_mir; i++) { + mir = mir_head + mir_size * i; /* Get next mirror */ + + /* Get the devt of the mirror disk */ + GET_VALUE(mir, mirror, dev, dm_dev); + GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); + + /* Get the offset of the mirror disk */ + GET_VALUE(mir, mirror, offset, offset); + + fprintf(fp, "%s(%llu)%s", buf, offset, + i == nr_mir - 1 ? "" : ","); + } + if (i != nr_mir) + fprintf(fp, " ERROR: dev are less than nr_mir:%d", nr_mir); +} + +static void +mirror_show_status(unsigned long target) +{ + unsigned int i, nr_mir, synced, nr_error; + unsigned long ms, mir_size, mir_head, mir, dm_dev; + char buf[BUFSIZE]; + + /* Get the address of struct mirror_set */ + GET_VALUE(target, dm_target, private, ms); + + /* Get the status info of the mirror_set */ + GET_VALUE(ms, mirror_set, in_sync, synced); + fprintf(fp, " in_sync:%d", synced); + + /* + * Display information for each mirror disks. + * + * mir_head = mirror_set.mirror. + * This is the head of struct mirror array. + */ + fprintf(fp, " dev:"); + mir_size = STRUCT_SIZE("struct mirror"); + GET_ADDR(ms, mirror_set, mirror, mir_head); + GET_VALUE(ms, mirror_set, nr_mirrors, nr_mir); + for (i = 0; i < nr_mir; i++) { + mir = mir_head + mir_size * i; /* Get next mirror */ + + /* Get the devt of the mirror disk */ + GET_VALUE(mir, mirror, dev, dm_dev); + GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); + + /* Get the offset of the mirror disk */ + GET_VALUE(mir, mirror, error_count, nr_error); + + fprintf(fp, "%s(%c,%d)%s", buf, nr_error ? 'D' : 'A', nr_error, + i == nr_mir - 1 ? "" : ","); + } + if (i != nr_mir) + fprintf(fp, " ERROR: dev are less than nr_mir:%d", nr_mir); +} + +static void +mirror_show_queue(unsigned long target) +{ + unsigned long ms, rlist, wlist, rhead, whead; + unsigned long rh, quis_head, rcov_head, quis_next, rcov_next; + + /* Get the address of struct mirror_set */ + GET_VALUE(target, dm_target, private, ms); + + /* Get the address of queued I/O lists in struct mirror_set */ + GET_ADDR(ms, mirror_set, reads, rlist); + GET_ADDR(ms, mirror_set, writes, wlist); + + /* Get the head of queued I/O lists */ + GET_VALUE(rlist, bio_list, head, rhead); + GET_VALUE(wlist, bio_list, head, whead); + fprintf(fp, " %s", rhead ? "reads" : "(reads)"); + fprintf(fp, " %s", whead ? "writes" : "(writes)"); + + /* Get the address of the struct region_hash */ + GET_ADDR(ms, mirror_set, rh, rh); + + /* Get the address of recover region lists in struct region_hash */ + GET_ADDR(rh, region_hash, quiesced_regions, quis_head); + GET_ADDR(rh, region_hash, recovered_regions, rcov_head); + + /* Get the head of recover region lists */ + quis_next = get_next_from_list_head(quis_head); + rcov_next = get_next_from_list_head(rcov_head); + + fprintf(fp, " %s", quis_next != quis_head ? "quiesced" : "(quiesced)"); + fprintf(fp, " %s", rcov_next != rcov_head ? "recovered" : "(recovered)"); +} + +static struct dminfo_target_analyzer mirror_analyzer = { + .target_name = "mirror", + .ready = mirror_ready, + .show_table = mirror_show_table, + .show_status = mirror_show_status, + .show_queue = mirror_show_queue +}; + +/* + * multipath target + */ +static int +multipath_ready(void) +{ + static int debuginfo = 0; + + if (debuginfo) + return 1; + + if (STRUCT_EXISTS("struct multipath")) { + debuginfo = 1; + return 1; + } else + fprintf(fp, "No such struct info: multipath"); + + return 0; +} + +static void +multipath_show_table(unsigned long target) +{ + int i, j; + unsigned int queue_if_no_path, nr_pgs, pg_id, nr_paths; + unsigned long mp, hwh, hwh_type, ps, ps_type, path, dm_dev; + unsigned long pg_head, pg_next, pg_last; + unsigned long path_head, path_next, path_last; + char name[BUFSIZE]; + + /* Get the address of struct multipath */ + GET_VALUE(target, dm_target, private, mp); + + /* Get features information */ + GET_VALUE(mp, multipath, queue_if_no_path, queue_if_no_path); + + /* Get the hardware-handler information */ + GET_ADDR(mp, multipath, hw_handler, hwh); + GET_VALUE(hwh, hw_handler, type, hwh_type); + if (hwh_type) + GET_PTR_STR(hwh_type, hw_handler_type, name, name, BUFSIZE); + else + strcpy(name, "none"); + + /* Get the number of priority groups */ + GET_VALUE(mp, multipath, nr_priority_groups, nr_pgs); + + fprintf(fp, " queue_if_no_path:%d hwh:%s nr_pgs:%d\n", + queue_if_no_path, name, nr_pgs); + + /* Display information for each priority group */ + fprintf(fp, " %-2s %-13s %-8s %s", + "PG", "PATH_SELECTOR", "NR_PATHS", "PATHS"); + GET_ADDR(mp, multipath, priority_groups, pg_head); + i = 0; + list_for_each (pg_next, pg_head, pg_last) { + /* pg_next == struct priority_group */ + + /* Get the index of the priority group */ + GET_VALUE(pg_next, priority_group, pg_num, pg_id); + + /* Get the name of path selector */ + GET_ADDR(pg_next, priority_group, ps, ps); + GET_VALUE(ps, path_selector, type, ps_type); + GET_PTR_STR(ps_type, path_selector_type, name, name, BUFSIZE); + + /* Get the number of paths in the priority group */ + GET_VALUE(pg_next, priority_group, nr_pgpaths, nr_paths); + + fprintf(fp, "\n %-2d %-13s %-8d ", pg_id, name, nr_paths); + + /* Display information for each path */ + GET_ADDR(pg_next, priority_group, pgpaths, path_head); + j = 0; + list_for_each (path_next, path_head, path_last) { + /* path_next == struct pgpath */ + + /* Get the devt of the pgpath */ + GET_ADDR(path_next, pgpath, path, path); + GET_VALUE(path, path, dev, dm_dev); + GET_STR(dm_dev, dm_dev, name, name, BUFSIZE); + + fprintf(fp, " %s", name); + j++; + } + if (j != nr_paths) + fprintf(fp, " ERROR: paths are less than nr_paths:%d", + nr_paths); + i++; + } + if (i != nr_pgs) + fprintf(fp, " ERROR: pgs are less than nr_pgs:%d", nr_pgs); +} + +static void +multipath_show_status(unsigned long target) +{ + int i, j; + unsigned int queue_if_no_path, nr_pgs, pg_id, nr_paths; + unsigned int bypassed_pg, path_active, nr_fails; + unsigned long mp, hwh, hwh_type, cur_pg, path, dm_dev; + unsigned long pg_head, pg_next, pg_last; + unsigned long path_head, path_next, path_last; + char buf[BUFSIZE], path_status; + + /* Get the address of struct multipath */ + GET_VALUE(target, dm_target, private, mp); + + /* Get features information */ + GET_VALUE(mp, multipath, queue_if_no_path, queue_if_no_path); + + /* Get the hardware-handler information */ + GET_ADDR(mp, multipath, hw_handler, hwh); + GET_VALUE(hwh, hw_handler, type, hwh_type); + if (hwh_type) + GET_PTR_STR(hwh_type, hw_handler_type, name, buf, BUFSIZE); + else + strcpy(buf, "none"); + + /* Get the number of priority groups */ + GET_VALUE(mp, multipath, nr_priority_groups, nr_pgs); + + fprintf(fp, " queue_if_no_path:%d hwh:%s nr_pgs:%d\n", + queue_if_no_path, buf, nr_pgs); + + /* Display information for each priority group */ + fprintf(fp, " %-2s %-9s %-8s %s", + "PG", "PG_STATUS", "NR_PATHS", "PATHS"); + GET_ADDR(mp, multipath, priority_groups, pg_head); + i = 0; + list_for_each (pg_next, pg_head, pg_last) { + /* pg_next == struct priority_group */ + + /* Get the index of the priority group */ + GET_VALUE(pg_next, priority_group, pg_num, pg_id); + + /* Get the status of the priority group */ + GET_VALUE(pg_next, priority_group, bypassed, bypassed_pg); + if (bypassed_pg) + strcpy(buf, "disabled"); + else { + GET_VALUE(mp, multipath, current_pg, cur_pg); + if (pg_next == cur_pg) + strcpy(buf, "active"); + else + strcpy(buf, "enabled"); + } + + /* Get the number of paths in the priority group */ + GET_VALUE(pg_next, priority_group, nr_pgpaths, nr_paths); + + fprintf(fp, "\n %-2d %-9s %-8d ", pg_id, buf, nr_paths); + + /* Display information for each path */ + GET_ADDR(pg_next, priority_group, pgpaths, path_head); + j = 0; + list_for_each (path_next, path_head, path_last) { + /* path_next == struct pgpath */ + + /* Get the devt of the pgpath */ + GET_ADDR(path_next, pgpath, path, path); + GET_VALUE(path, path, dev, dm_dev); + GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); + + /* Get the status of the path */ + GET_VALUE(path, path, is_active, path_active); + GET_VALUE(path_next, pgpath, fail_count, nr_fails); + path_status = path_active ? 'A' : 'F'; + + fprintf(fp, " %s(%c,%u)", buf, path_status, nr_fails); + j++; + } + if (j != nr_paths) + fprintf(fp, " ERROR: paths are less than nr_paths:%d", + nr_paths); + i++; + } + if (i != nr_pgs) + fprintf(fp, " ERROR: pgs are less than nr_pgs:%d", nr_pgs); +} + +static void +multipath_show_queue(unsigned long target) +{ + unsigned int queue_size; + unsigned long mp; + + /* Get the address of struct multipath */ + GET_VALUE(target, dm_target, private, mp); + + /* Get the size of queued I/Os in this 'target' */ + GET_VALUE(mp, multipath, queue_size, queue_size); + + fprintf(fp, " queue_size:%d", queue_size); +} + +static struct dminfo_target_analyzer multipath_analyzer = { + .target_name = "multipath", + .ready = multipath_ready, + .show_table = multipath_show_table, + .show_status = multipath_show_status, + .show_queue = multipath_show_queue +}; + +/* + * crypt target + */ +static int +crypt_ready(void) +{ + static int debuginfo = 0; + + if (debuginfo) + return 1; + + if (STRUCT_EXISTS("struct crypt_config")) { + debuginfo = 1; + return 1; + } else + fprintf(fp, "No such struct info: crypt_config"); + + return 0; +} + +#define DMINFO_CRYPTO_TFM_MODE_ECB 0x00000001 +#define DMINFO_CRYPTO_TFM_MODE_CBC 0x00000002 + +static void +crypt_show_table(unsigned long target) +{ + int i, cit_mode, key_size; + unsigned long cc, tfm, crt_alg, cipher, iv_mode, dm_dev; + char buf[BUFSIZE], *chainmode; + + /* Get the address of struct crypt_config */ + GET_VALUE(target, dm_target, private, cc); + + /* Get the cipher name of the crypt_tfm */ + GET_VALUE(cc, crypt_config, tfm, tfm); + GET_VALUE(tfm, crypto_tfm, __crt_alg, crt_alg); + GET_STR(crt_alg, crypto_alg, cra_name, buf, BUFSIZE); + fprintf(fp, " type:%s", buf); + + /* Get the cit_mode of the crypt_tfm */ + GET_ADDR(tfm, crypto_tfm, crt_u, cipher); + GET_VALUE(cipher, cipher_tfm, cit_mode, cit_mode); + + if (MEMBER_EXISTS("struct crypt_config", "iv_mode")) { + if (cit_mode == DMINFO_CRYPTO_TFM_MODE_CBC) + chainmode = "cbc"; + else if (cit_mode == DMINFO_CRYPTO_TFM_MODE_ECB) + chainmode = "ecb"; + else + chainmode = "unknown"; + + /* Get the iv_mode of the crypt_config */ + GET_VALUE(cc, crypt_config, iv_mode, iv_mode); + if (iv_mode) { + GET_PTR_STR(cc, crypt_config, iv_mode, buf, BUFSIZE); + fprintf(fp, "-%s-%s", chainmode, buf); + } else + fprintf(fp, "-%s", chainmode); + + } else { + /* Compatibility mode for old dm-crypt cipher strings */ + if (cit_mode == DMINFO_CRYPTO_TFM_MODE_CBC) + chainmode = "plain"; + else if (cit_mode == DMINFO_CRYPTO_TFM_MODE_ECB) + chainmode = "ecb"; + else + chainmode = "unknown"; + + fprintf(fp, "-%s", chainmode); + } + + /* Get the devt of the crypt_config */ + GET_VALUE(cc, crypt_config, dev, dm_dev); + GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); + fprintf(fp, " dev:%s", buf); + + /* + * Get the key of the crypt_config. + */ + GET_VALUE(cc, crypt_config, key_size, key_size); + GET_STR(cc, crypt_config, key, buf, MIN(key_size + 1, BUFSIZE)); + fprintf(fp, " key:"); + for (i = 0; i < key_size; i++) + fprintf(fp, "%02x", (unsigned char)buf[i]); +} + +static void +crypt_show_status(unsigned long target) +{ + /* crypt target has no status */ + fprintf(fp, " No status info"); +} + +static void +crypt_show_queue(unsigned long target) +{ + /* crypt target has no queue */ + fprintf(fp, " No queue info"); +} + +static struct dminfo_target_analyzer crypt_analyzer = { + .target_name = "crypt", + .ready = crypt_ready, + .show_table = crypt_show_table, + .show_status = crypt_show_status, + .show_queue = crypt_show_queue +}; + +/* + * stripe target + */ +static int +stripe_ready(void) +{ + static int debuginfo = 0; + + if (debuginfo) + return 1; + + if (STRUCT_EXISTS("struct stripe_c")) { + debuginfo = 1; + return 1; + } else + fprintf(fp, "No such struct info: stripe_c"); + + return 0; +} + +static void +stripe_show_table(unsigned long target) +{ + unsigned int i, n_stripe; + unsigned long sc, stripe_size, s, head, dm_dev; + unsigned long long mask; + char buf[BUFSIZE]; + + /* Get the address of struct stripe_c */ + GET_VALUE(target, dm_target, private, sc); + + /* Get the chunk_size of the stripe_c */ + GET_VALUE(sc, stripe_c, chunk_mask, mask); + fprintf(fp, " chunk_size:%llu", mask + 1); + + /* + * Display the information of each stripe disks. + * + * head = stripe_c.stripe. + * This is the head of struct stripe array. + */ + stripe_size = STRUCT_SIZE("struct stripe"); + GET_ADDR(sc, stripe_c, stripe, head); + GET_VALUE(sc, stripe_c, stripes, n_stripe); + fprintf(fp, " dev:"); + for (i = 0; i < n_stripe; i++) { + s = head + stripe_size * i; /* Get next stripe */ + + /* Get the devt of the stripe disk */ + GET_VALUE(s, stripe, dev, dm_dev); + GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); + + fprintf(fp, "%s%s", buf, i == n_stripe - 1 ? "" : ","); + } + if (i != n_stripe) + fprintf(fp, " ERROR: dev are less than n_stripe:%d", n_stripe); +} + +static void +stripe_show_status(unsigned long target) +{ + /* stripe target has no status */ + fprintf(fp, " No status info"); +} + +static void +stripe_show_queue(unsigned long target) +{ + /* stripe target has no queue */ + fprintf(fp, " No queue info"); +} + +static struct dminfo_target_analyzer stripe_analyzer = { + .target_name = "striped", + .ready = stripe_ready, + .show_table = stripe_show_table, + .show_status = stripe_show_status, + .show_queue = stripe_show_queue +}; + +/* + * snapshot target + */ +static int +snapshot_ready(void) +{ + static int debuginfo = 0; + + if (debuginfo) + return 1; + + if (STRUCT_EXISTS("struct dm_snapshot")) { + debuginfo = 1; + return 1; + } else + fprintf(fp, "No such struct info: dm_snapshot"); + + return 0; +} + +static void +snapshot_show_table(unsigned long target) +{ + unsigned long snap, orig_dev, cow_dev; + unsigned long long chunk_size; + char orig_name[BUFSIZE], cow_name[BUFSIZE], type; + + /* Get the address of struct dm_snapshot */ + GET_VALUE(target, dm_target, private, snap); + + /* Get snapshot parameters of the dm_snapshot */ + GET_VALUE(snap, dm_snapshot, origin, orig_dev); + GET_STR(orig_dev, dm_dev, name, orig_name, BUFSIZE); + GET_VALUE(snap, dm_snapshot, cow, cow_dev); + GET_STR(cow_dev, dm_dev, name, cow_name, BUFSIZE); + GET_VALUE(snap, dm_snapshot, type, type); + GET_VALUE(snap, dm_snapshot, chunk_size, chunk_size); + + fprintf(fp, " orig:%s cow:%s type:%c chunk_size:%llu", + orig_name, cow_name, type, chunk_size); +} + +static void +snapshot_show_status(unsigned long target) +{ + int valid; + unsigned long snap; + + /* Get the address of struct dm_snapshot */ + GET_VALUE(target, dm_target, private, snap); + + /* Get snapshot parameters of the dm_snapshot */ + GET_VALUE(snap, dm_snapshot, valid, valid); + + fprintf(fp, " vaild:%d", valid); +} + +static void +snapshot_show_queue(unsigned long target) +{ + fprintf(fp, " No queue info"); +} + +static struct dminfo_target_analyzer snapshot_analyzer = { + .target_name = "snapshot", + .ready = snapshot_ready, + .show_table = snapshot_show_table, + .show_status = snapshot_show_status, + .show_queue = snapshot_show_queue +}; + +/* + * snapshot-origin target + */ +static int +origin_ready(void) +{ + return 1; +} + +static void +origin_show_table(unsigned long target) +{ + unsigned long dm_dev; + char buf[BUFSIZE]; + + /* Get the name of the struct dm_dev */ + GET_VALUE(target, dm_target, private, dm_dev); + GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE); + + fprintf(fp, " orig_dev:%s", buf); +} + +static void +origin_show_status(unsigned long target) +{ + /* snapshot-origin target has no status */ + fprintf(fp, " No status info"); +} + +static void +origin_show_queue(unsigned long target) +{ + /* snapshot-origin target has no queue */ + fprintf(fp, " No queue info"); +} + +static struct dminfo_target_analyzer snapshot_origin_analyzer = { + .target_name = "snapshot-origin", + .ready = origin_ready, + .show_table = origin_show_table, + .show_status = origin_show_status, + .show_queue = origin_show_queue +}; + +/* + * Core part of dminfo + */ +#define DMINFO_LIST 0 +#define DMINFO_DEPS 1 +#define DMINFO_TABLE 2 +#define DMINFO_STATUS 3 +#define DMINFO_QUEUE 4 + +static int +dm_core_ready(void) +{ + static int debuginfo = 0; + + if (debuginfo) + return 1; + + if (STRUCT_EXISTS("struct hash_cell")) { + debuginfo = 1; + return 1; + } else + fprintf(fp, "No such struct info: hash_cell\n"); + + return 0; +} + +/* Display dependency information of the 'table' */ +static void +dminfo_show_deps(unsigned long table) +{ + int major, minor, count; + unsigned long head, next, last, dev, bdev; + char buf[BUFSIZE]; + + /* head = dm_table.devices */ + GET_ADDR(table, dm_table, devices, head); + + fprintf(fp, " %-3s %-3s %-16s %-5s %s\n", + "MAJ", "MIN", "GENDISK", "COUNT", "DEVNAME"); + + list_for_each (next, head, last) { + /* Get dependency information. (next == struct *dm_dev) */ + GET_VALUE(next, dm_dev, count, count); + GET_VALUE(next, dm_dev, bdev, bdev); + GET_VALUE(bdev, block_device, bd_disk, dev); + GET_VALUE(dev, gendisk, major, major); + GET_VALUE(dev, gendisk, first_minor, minor); + GET_STR(dev, gendisk, disk_name, buf, BUFSIZE); + + fprintf(fp, " %-3d %-3d %-16lx %-5d %s\n", + major, minor, dev, count, buf); + } +} + +/* + * Display target specific information in the 'table', if the target + * analyzer is registered and available. + */ +static void +dminfo_show_details(unsigned long table, unsigned int num_targets, int info_type) +{ + unsigned int i; + unsigned long head, target_size, target, target_type; + struct dminfo_target_analyzer *ta; + char buf[BUFSIZE]; + + /* + * head = dm_table.targets. + * This is the head of struct dm_target array. + */ + GET_VALUE(table, dm_table, targets, head); + target_size = STRUCT_SIZE("struct dm_target"); + + fprintf(fp, " %-16s %-11s %s\n", + "TARGET", "TARGET_TYPE", "PRIVATE_DATA"); + + for (i = 0; i < num_targets; i++, fprintf(fp, "\n")) { + target = head + target_size * i; /* Get next target */ + + /* Get target information */ + GET_VALUE(target, dm_target, type, target_type); + GET_PTR_STR(target_type, target_type, name, buf, BUFSIZE); + + fprintf(fp, " %-16lx %-11s", target, buf); + + if (!(ta = find_target_analyzer(buf)) || !ta->ready + || !ta->ready()) + continue; + + switch (info_type) { + case DMINFO_TABLE: + if (ta->show_table) + ta->show_table(target); + break; + case DMINFO_STATUS: + if (ta->show_status) + ta->show_status(target); + break; + case DMINFO_QUEUE: + if (ta->show_queue) + ta->show_queue(target); + break; + default: + break; + } + } + + if (i != num_targets) + fprintf(fp, " ERROR: targets are less than num_targets:%d", + num_targets); +} + +/* + * Display lists (and detail information if specified) of existing + * dm devices. + */ +static void +dminfo_show_list(int additional_info) +{ + int i, major, minor, array_len; + unsigned int num_targets; + unsigned long _name_buckets, head, next, last, md, dev, table; + char buf[BUFSIZE]; + + _name_buckets = symbol_value("_name_buckets"); + array_len = get_array_length("_name_buckets", NULL, 0); + + if (additional_info == DMINFO_LIST) + fprintf(fp, "%-3s %-3s %-16s %-16s %-7s %s\n", + "MAJ", "MIN", "MAP_DEV", "DM_TABLE", + "TARGETS", "MAPNAME"); + + for (i = 0; i < array_len; i++) { + /* head = _name_buckets[i] */ + head = _name_buckets + (i * SIZE(list_head)); + + list_for_each (next, head, last) { /* next == hash_cell */ + /* Get device and table information */ + GET_PTR_STR(next, hash_cell, name, buf, BUFSIZE); + GET_VALUE(next, hash_cell, md, md); + GET_VALUE(md, mapped_device, disk, dev); + GET_VALUE(dev, gendisk, major, major); + GET_VALUE(dev, gendisk, first_minor, minor); + GET_VALUE(md, mapped_device, map, table); + GET_VALUE(table, dm_table, num_targets, num_targets); + + if (additional_info != DMINFO_LIST) + fprintf(fp, "%-3s %-3s %-16s %-16s %-7s %s\n", + "MAJ", "MIN", "MAP_DEV", "DM_TABLE", + "TARGETS", "MAPNAME"); + + fprintf(fp, "%-3d %-3d %-16lx %-16lx %-7d %s\n", + major, minor, md, table, num_targets, buf); + + switch(additional_info) { + case DMINFO_DEPS: + dminfo_show_deps(table); + break; + case DMINFO_TABLE: + case DMINFO_STATUS: + case DMINFO_QUEUE: + dminfo_show_details(table, num_targets, + additional_info); + break; + default: + break; + } + + if (additional_info != DMINFO_LIST) + fprintf(fp, "\n"); + } + } +} + +/* + * Display the original bio information for the 'bio'. + * If the 'bio' is for dm devices, the original bio information is pointed + * by bio.bi_private as struct target_io. + */ +static void +dminfo_show_bio(unsigned long bio) +{ + int major, minor; + unsigned long target_io, dm_io, dm_bio, md, dev; + char buf[BUFSIZE]; + + /* Get original bio and device information */ + GET_VALUE(bio, bio, bi_private, target_io); + GET_VALUE(target_io, target_io, io, dm_io); + GET_VALUE(dm_io, dm_io, bio, dm_bio); + GET_VALUE(dm_io, dm_io, md, md); + GET_VALUE(md, mapped_device, disk, dev); + GET_VALUE(dev, gendisk, major, major); + GET_VALUE(dev, gendisk, first_minor, minor); + GET_STR(dev, gendisk, disk_name, buf, BUFSIZE); + + fprintf(fp, "%-16s %-3s %-3s %-16s %s\n", + "DM_BIO_ADDRESS", "MAJ", "MIN", "MAP_DEV", "DEVNAME"); + fprintf(fp, "%-16lx %-3d %-3d %-16lx %s\n", + dm_bio, major, minor, md, buf); +} + +static void +cmd_dminfo(void) +{ + int c, additional_info = DMINFO_LIST; + unsigned long bio; + + if (!dm_core_ready()) + return; + + /* Parse command line option */ + while ((c = getopt(argcnt, args, "b:dlqst")) != EOF) { + switch(c) + { + case 'b': + bio = stol(optarg, FAULT_ON_ERROR, NULL); + dminfo_show_bio(bio); + return; + case 'd': + additional_info = DMINFO_DEPS; + break; + case 'l': + additional_info = DMINFO_LIST; + break; + case 'q': + additional_info = DMINFO_QUEUE; + break; + case 's': + additional_info = DMINFO_STATUS; + break; + case 't': + additional_info = DMINFO_TABLE; + break; + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + dminfo_show_list(additional_info); +} + +/* + * dminfo help + */ +static char *help_dminfo[] = { + "dminfo", /* command name */ + "device mapper (dm) information", /* short description */ + "[-b bio | -d | -l | -q | -s | -t]", /* argument synopsis */ + " This command displays information about device-mapper mapped ", + " devices (dm devices).", + " If no argument is entered, displays lists of existing dm devices.", + " It's same as -l option.", + "", + " -b bio displays the information of the dm device which the bio", + " is submitted in. If the bio isn't for dm devices,", + " results will be error.", + " -d displays dependency information for existing dm devices.", + " -l displays lists of existing dm devices.", + " -q displays queued I/O information for each target of", + " existing dm devices.", + " -s displays status information for each target of existing", + " dm devices.", + " -t displays table information for each target of existing", + " dm devices.", + "", + "EXAMPLE", + " Display lists of dm devices. \"MAP_DEV\" is the address of the", + " struct mapped_device. \"DM_TABLE\" is the address of the struct", + " dm_table. \"TARGETS\" is the number of targets which are in", + " the struct dm_table.", + "", + " %s> dminfo", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 8 c4866c80 c4866280 1 vg0-snap0", + " 253 6 f6a04a80 f6a04580 1 vg0-lv0-real", + " 253 0 c4840380 c4841880 1 mp0", + " 253 5 f7c50c80 c488e480 1 via_cbeheddbdd", + " 253 7 c4866a80 c4866380 1 vg0-snap0-cow", + " 253 4 d441e280 c919ed80 1 dummy1", + " 253 3 f5dc4280 cba81d80 1 dummy0", + " 253 2 f7c53180 c4866180 1 vg0-lv0", + " 253 1 f746d280 f746cd80 1 mp0p1", + "", + " Display the dm device information which the bio is submitted in.", + " The bio (ceacee80) is a clone of the bio (ceacee00) which is", + " submitted in the dm-3 (dummy0). And the bio (ceacee00) is a clone", + " of the bio (ceaced80) which is submitted in the dm-4 (dummy1), too.", + " The bio (ceaced80) is the original bio.", + "", + " %s> dminfo -b ceacee80", + " DM_BIO_ADDRESS MAJ MIN MAP_DEV DEVNAME", + " ceacee00 253 3 f5dc4280 dm-3", + " crash> dminfo -b ceacee00", + " DM_BIO_ADDRESS MAJ MIN MAP_DEV DEVNAME", + " ceaced80 253 4 d441e280 dm-4", + " crash> dminfo -b ceaced80", + " dminfo: invalid kernel virtual address: 64 type: \"GET_VALUE: dm_io.bio\"", + "", + " Display dependency information for each target.", + " The vg0-snap0 depends on thd dm-6 (vg0-lv0-real) and the dm-7", + " (vg0-snap0-cow)", + "", + " %s> dminfo -d", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 8 c4866c80 c4866280 1 vg0-snap0", + " MAJ MIN GENDISK COUNT DEVNAME", + " 253 7 c4866980 1 dm-7", + " 253 6 f6a04280 1 dm-6", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 6 f6a04a80 f6a04580 1 vg0-lv0-real", + " MAJ MIN GENDISK COUNT DEVNAME", + " 8 0 f7f24c80 1 sda", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 7 c4866a80 c4866380 1 vg0-snap0-cow", + " MAJ MIN GENDISK COUNT DEVNAME", + " 8 0 f7f24c80 1 sda", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 2 f7c53180 c4866180 1 vg0-lv0", + " MAJ MIN GENDISK COUNT DEVNAME", + " 253 6 f6a04280 1 dm-6", + "", + " Display queued I/O information for each target.", + " The information is displayed under the \"PRIVATE_DATA\" column.", + "", + " %s> dminfo -q", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 5 f7c50c80 c488e480 1 via_cbeheddbdd", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f8961080 mirror (reads) (writes) (quiesced) (recovered)", + "", + " --------------------------------------------------------------", + " \"reads/writes\" are members of the struct mirror_set, and", + " \"quiesced/recovered\" are members of the struct region_hash.", + " If the list is empty, the member is bracketed by \"()\".", + " --------------------------------------------------------------", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 0 c4840380 c4841880 1 mp0", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f8802080 multipath queue_size:0", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 1 f746d280 f746cd80 1 mp0p1", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f8821080 linear No queue info", + "", + " Display status information for each target.", + " The information is displayed under the \"PRIVATE_DATA\" column.", + "", + " %s> dminfo -s", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 0 c4840380 c4841880 1 mp0", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f8802080 multipath queue_if_no_path:0 hwh:none nr_pgs:1", + " PG PG_STATUS NR_PATHS PATHS", + " 1 active 2 8:16(A,0) 8:32(A,0)", + "", + " --------------------------------------------------------------", + " Format of \"PATHS\": :(,)", + " Status: A:active, F:faulty", + " Fail_count: the value of the struct pgpath.fail_count", + " --------------------------------------------------------------", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 5 f7c50c80 c488e480 1 via_cbeheddbdd", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f8961080 mirror in_sync:1 dev:8:16(A,0),8:32(A,0)", + "", + " --------------------------------------------------------------", + " Format of \"dev\": :(,)", + " Status: A:active, D:degraded", + " Error_count: the value of the struct mirror.error_count", + " --------------------------------------------------------------", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 1 f746d280 f746cd80 1 mp0p1", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f8821080 linear No status info", + "", + " Display table information for each target.", + " The information is displayed under the \"PRIVATE_DATA\" column.", + "", + " %s> dminfo -t", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 8 c4866c80 c4866280 1 vg0-snap0", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f89b4080 snapshot orig:253:6 cow:253:7 type:P chunk_size:16", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 6 f6a04a80 f6a04580 1 vg0-lv0-real", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f890f080 linear begin:0 len:204800 dev:8:5 offset:384", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 0 c4840380 c4841880 1 mp0", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f8802080 multipath queue_if_no_path:0 hwh:none nr_pgs:1", + " PG PATH_SELECTOR NR_PATHS PATHS", + " 1 round-robin 2 8:16 8:32", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 5 f7c50c80 c488e480 1 via_cbeheddbdd", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f8961080 mirror log:core dev:8:16(0),8:32(0)", + "", + " --------------------------------------------------------------", + " Format of \"dev\": :()", + " Offset: the value of the struct mirror.offset", + " --------------------------------------------------------------", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 7 c4866a80 c4866380 1 vg0-snap0-cow", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f899d080 linear begin:0 len:8192 dev:8:5 offset:205184", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 2 f7c53180 c4866180 1 vg0-lv0", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f8bbc080 snapshot-origin orig_dev:253:6", + "", + " MAJ MIN MAP_DEV DM_TABLE TARGETS MAPNAME", + " 253 1 f746d280 f746cd80 1 mp0p1", + " TARGET TARGET_TYPE PRIVATE_DATA", + " f8821080 linear begin:0 len:2040192 dev:253:0 offset:63", + NULL +}; + +/* + * Registering command extension + */ + +static struct command_table_entry command_table[] = { + {"dminfo", cmd_dminfo, help_dminfo, 0}, + {NULL, NULL, NULL, 0}, +}; + +void __attribute__((constructor)) +dminfo_init(void) +{ + register_extension(command_table); + + dminfo_register_target_analyzer(&zero_analyzer); + dminfo_register_target_analyzer(&error_analyzer); + dminfo_register_target_analyzer(&linear_analyzer); + dminfo_register_target_analyzer(&mirror_analyzer); + dminfo_register_target_analyzer(&multipath_analyzer); + dminfo_register_target_analyzer(&crypt_analyzer); + dminfo_register_target_analyzer(&stripe_analyzer); + dminfo_register_target_analyzer(&snapshot_analyzer); + dminfo_register_target_analyzer(&snapshot_origin_analyzer); +} + +void __attribute__((destructor)) +dminfo_fini(void) +{ +} diff --git a/extensions/echo.c b/extensions/echo.c new file mode 100644 index 00000000..ff1e09a3 --- /dev/null +++ b/extensions/echo.c @@ -0,0 +1,110 @@ +/* echo.c - simple example of a crash extension + * + * Copyright (C) 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2005, 2007, 2013 David Anderson + * Copyright (C) 2002-2005, 2007, 2013 Red Hat, Inc. 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. + */ + +#include "defs.h" /* From the crash source top-level directory */ + +void echo_init(void); /* constructor function */ +void echo_fini(void); /* destructor function (optional) */ + +void cmd_echo(void); /* Declare the commands and their help data. */ +char *help_echo[]; + +static struct command_table_entry command_table[] = { + { "echo", cmd_echo, help_echo, 0}, /* One or more commands, */ + { NULL }, /* terminated by NULL, */ +}; + + +void __attribute__((constructor)) +echo_init(void) /* Register the command set. */ +{ + register_extension(command_table); +} + +/* + * This function is called if the shared object is unloaded. + * If desired, perform any cleanups here. + */ +void __attribute__((destructor)) +echo_fini(void) { } + + +/* + * Arguments are passed to the command functions in the global args[argcnt] + * array. See getopt(3) for info on dash arguments. Check out defs.h and + * other crash commands for usage of the myriad of utility routines available + * to accomplish what your task. + */ +void +cmd_echo(void) +{ + int c; + + while ((c = getopt(argcnt, args, "")) != EOF) { + switch(c) + { + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + while (args[optind]) + fprintf(fp, "%s ", args[optind++]); + + fprintf(fp, "\n"); +} + +/* + * The optional help data is simply an array of strings in a defined format. + * For example, the "help echo" command will use the help_echo[] string + * array below to create a help page that looks like this: + * + * NAME + * echo - echoes back its arguments + * + * SYNOPSIS + * echo arg ... + * + * DESCRIPTION + * This command simply echoes back its arguments. + * + * EXAMPLE + * Echo back all command arguments: + * + * crash> echo hello, world + * hello, world + * + */ + +char *help_echo[] = { + "echo", /* command name */ + "echoes back its arguments", /* short description */ + "arg ...", /* argument synopsis, or " " if none */ + + " This command simply echoes back its arguments.", + "\nEXAMPLE", + " Echo back all command arguments:\n", + " crash> echo hello, world", + " hello, world", + NULL +}; + + diff --git a/extensions/eppic.c b/extensions/eppic.c new file mode 100644 index 00000000..90f8247e --- /dev/null +++ b/extensions/eppic.c @@ -0,0 +1,4 @@ +/* + Place holder for proper working of the extension Makefile. + Eppic crash application file is in eppic/applications/crash/eppic.c +*/ diff --git a/extensions/eppic.mk b/extensions/eppic.mk new file mode 100644 index 00000000..7421ebcf --- /dev/null +++ b/extensions/eppic.mk @@ -0,0 +1,72 @@ +# +# 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. + +TARGET_FLAGS = -D$(TARGET) +ifeq ($(TARGET), PPC64) + TARGET_FLAGS += -m64 +endif +ifeq ($(TARGET), ARM) + TARGET_FLAGS += -m32 +endif +ifeq ($(TARGET), X86) + TARGET_FLAGS += -m32 +endif + +APPFILE=eppic/applications/crash/eppic.c +GOOGLE := $(shell ping -c 1 code.google.com | grep "1 received") +GIT := $(shell which git 2> /dev/null) + +all: + @if [ -f /usr/bin/flex ] && [ -f /usr/bin/bison ]; then \ + if [ -f ../$(GDB)/crash.target ]; \ + then \ + if [ ! -f $(APPFILE) ]; \ + then \ + if [ -f "$(GIT)" ]; \ + then \ + if [ -n "$(EPPIC_GIT_URL)" ]; then \ + git clone "$(EPPIC_GIT_URL)" eppic; \ + else \ + if [ -n "$(GOOGLE)" ] ; then \ + git clone https://code.google.com/p/eppic eppic; \ + fi; \ + fi; \ + else \ + if [ ! -f "$(GIT)" ]; then \ + echo "eppic.so: git command is needed for pulling eppic extension code"; \ + fi; \ + fi; \ + fi; \ + if [ -f $(APPFILE) ]; \ + then \ + make -f eppic.mk eppic.so; \ + else \ + echo "eppic.so: failed to pull eppic code from git repo"; \ + fi; \ + else \ + echo "eppic.so: build failed: requires the crash $(GDB) module"; \ + fi ;\ + else \ + echo "eppic.so: build failed: requires /usr/bin/flex and /usr/bin/bison"; \ + fi + +lib-eppic: + cd eppic/libeppic && make + +eppic.so: ../defs.h $(APPFILE) lib-eppic + gcc -g -Ieppic/libeppic -I../$(GDB)/gdb -I../$(GDB)/bfd -I../$(GDB)/include -I../$(GDB)/gdb/config -I../$(GDB)/gdb/common -I../$(GDB) -nostartfiles -shared -rdynamic -o eppic.so $(APPFILE) -fPIC $(TARGET_FLAGS) $(GDB_FLAGS) -Leppic/libeppic -leppic + +clean: + if [ -d eppic/libeppic ]; \ + then \ + cd eppic/libeppic && make -i clean; \ + fi + rm -f eppic.so diff --git a/extensions/snap.c b/extensions/snap.c new file mode 100644 index 00000000..7bbce4bb --- /dev/null +++ b/extensions/snap.c @@ -0,0 +1,752 @@ +/* snap.c - capture live memory into a kdump or netdump dumpfile + * + * Copyright (C) 2009, 2013 David Anderson + * Copyright (C) 2009, 2013 Red Hat, Inc. 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. + */ + +#include "defs.h" +#include +#include +#include + +void snap_init(void); +void snap_fini(void); + +void cmd_snap(void); +char *help_snap[]; + +static struct command_table_entry command_table[] = { + { "snap", cmd_snap, help_snap, 0 }, + { NULL } +}; + +static char *generate_elf_header(int, int, char *); +static int verify_paddr(physaddr_t); +static void init_ram_segments(void); +static int print_progress(const char *, ulong); + +#if defined(X86) || defined(X86_64) || defined(IA64) || defined(PPC64) +int supported = TRUE; +#else +int supported = FALSE; +#endif + +void __attribute__((constructor)) +snap_init(void) /* Register the command set. */ +{ + register_extension(command_table); +} + +void __attribute__((destructor)) +snap_fini(void) +{ +} + + +/* + * Just pass in an unused filename. + */ +void +cmd_snap(void) +{ + int c, fd, n; + physaddr_t paddr; + size_t offset; + char *buf; + char *filename; + struct node_table *nt; + int type; + char *elf_header; + Elf64_Phdr *load; + int load_index; + + if (!supported) + error(FATAL, "command not supported on the %s architecture\n", + pc->machine_type); + + filename = NULL; + buf = GETBUF(PAGESIZE()); + type = KDUMP_ELF64; + + while ((c = getopt(argcnt, args, "n")) != EOF) { + switch(c) + { + case 'n': + if (machine_type("X86_64")) + option_not_supported('n'); + else + type = NETDUMP_ELF64; + break; + default: + argerrs++; + break; + } + } + + if (argerrs || !args[optind]) + cmd_usage(pc->curcmd, SYNOPSIS); + + while (args[optind]) { + if (filename) + cmd_usage(pc->curcmd, SYNOPSIS); + + if (file_exists(args[optind], NULL)) + error(FATAL, "%s: file already exists\n", args[optind]); + else if ((fd = open(args[optind], O_RDWR|O_CREAT, 0644)) < 0) + error(FATAL, args[optind]); + + filename = args[optind]; + optind++; + } + + if (!filename) + cmd_usage(pc->curcmd, SYNOPSIS); + + init_ram_segments(); + + if (!(elf_header = generate_elf_header(type, fd, filename))) + error(FATAL, "cannot generate ELF header\n"); + + load = (Elf64_Phdr *)(elf_header + sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr)); + load_index = machine_type("X86_64") || machine_type("IA64") ? 1 : 0; + + for (n = 0; n < vt->numnodes; n++) { + nt = &vt->node_table[n]; + paddr = nt->start_paddr; + offset = load[load_index + n].p_offset; + + for (c = 0; c < nt->size; c++, paddr += PAGESIZE()) { + if (!verify_paddr(paddr)) + continue; + if (!readmem(paddr, PHYSADDR, &buf[0], PAGESIZE(), + "memory page", QUIET|RETURN_ON_ERROR)) + continue; + + lseek(fd, (off_t)(paddr + offset - nt->start_paddr), SEEK_SET); + if (write(fd, &buf[0], PAGESIZE()) != PAGESIZE()) + error(FATAL, "write to dumpfile failed\n"); + + if (!print_progress(filename, BTOP(paddr))) + return; + } + } + + fprintf(stderr, "\r%s: [100%%] ", filename); + fprintf(fp, "\n"); + sprintf(buf, "/bin/ls -l %s\n", filename); + system(buf); + + FREEBUF(elf_header); + FREEBUF(buf); +} + + +char *help_snap[] = { + "snap", /* command name */ + "take a memory snapshot", /* short description */ + "[-n] dumpfile", /* filename */ + + " This command takes a snapshot of physical memory and creates an ELF vmcore.", + " The default vmcore is a kdump-style dumpfile. Supported on x86, x86_64,", + " ia64 and ppc64 architectures only.", + " ", + " -n create a netdump-style vmcore (n/a on x86_64).", + NULL +}; + +/* + * Architecture-specific and -generic ELF header data borrowed from the + * netdump.h file in the netdump package, modified slightly to also create + * a kdump-style vmcore. + */ + +/****************************************************************************** + * Elf core dumping * + ******************************************************************************/ + +/* + * Host-platform independent data + */ +#define ELF_PRARGSZ (80) /* Number of chars for args */ +struct elf_prpsinfo_64 +{ + char pr_state; /* numeric process state */ + char pr_sname; /* char for pr_state */ + char pr_zomb; /* zombie */ + char pr_nice; /* nice val */ + __u64 pr_flag; /* flags */ + __u32 pr_uid; + __u32 pr_gid; + __u32 pr_pid, pr_ppid, pr_pgrp, pr_sid; + /* Lots missing */ + char pr_fname[16]; /* filename of executable */ + char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */ +}; + +/* + * i386 specific + */ +struct user_regs_struct_i386 { + __u32 ebx, ecx, edx, esi, edi, ebp, eax; + __u16 ds, __ds, es, __es; + __u16 fs, __fs, gs, __gs; + __u32 orig_eax, eip; + __u16 cs, __cs; + __u32 eflags, esp; + __u16 ss, __ss; +}; + +#define ELF_NGREG_I386 (sizeof (struct user_regs_struct_i386) / sizeof(__u32)) +typedef __u32 elf_gregset_i386_t[ELF_NGREG_I386]; + +struct elf_prstatus_i386 { + char pad[72]; + elf_gregset_i386_t pr_reg; /* GP registers */ + __u32 pr_fpvalid; /* True if math co-processor being used. */ +}; + +/* + * x86_64 specific + */ +struct user_regs_struct_x86_64 { + __u64 r15,r14,r13,r12,rbp,rbx,r11,r10; + __u64 r9,r8,rax,rcx,rdx,rsi,rdi,orig_rax; + __u64 rip,cs,eflags; + __u64 rsp,ss; + __u64 fs_base, gs_base; + __u64 ds,es,fs,gs; +}; + +#define ELF_NGREG_X86_64 (sizeof (struct user_regs_struct_x86_64) / sizeof(__u64)) +typedef __u64 elf_gregset_x86_64_t[ELF_NGREG_X86_64]; + +struct elf_prstatus_x86_64 { + char pad[112]; + elf_gregset_x86_64_t pr_reg; /* GP registers */ + __u32 pr_fpvalid; /* True if math co-processor being used. */ +}; + +/* + * ppc64 specific + */ +struct user_regs_struct_ppc64 { + __u64 gpr[32]; + __u64 nip; + __u64 msr; + __u64 orig_gpr3; + __u64 ctr; + __u64 link; + __u64 xer; + __u64 ccr; + __u64 softe; + __u64 trap; + __u64 dar; + __u64 dsisr; + __u64 result; +}; + +#define ELF_NGREG_PPC64 (sizeof (struct user_regs_struct_ppc64) / sizeof(__u64)) +typedef __u64 elf_gregset_ppc64_t[ELF_NGREG_PPC64]; + +struct elf_prstatus_ppc64 { + char pad[112]; + elf_gregset_ppc64_t pr_reg; /* GP registers */ + __u32 pr_fpvalid; /* True if math co-processor being used. */ +}; + +/* + * ia64 specific + */ +struct _ia64_fpreg { + union { + __u64 bits[2]; + } u; +} __attribute__ ((aligned (16))); + +struct user_regs_struct_ia64 { + /* The following registers are saved by SAVE_MIN: */ + __u64 b6; /* scratch */ + __u64 b7; /* scratch */ + + __u64 ar_csd; /* used by cmp8xchg16 (scratch) */ + __u64 ar_ssd; /* reserved for future use (scratch) */ + + __u64 r8; /* scratch (return value register 0) */ + __u64 r9; /* scratch (return value register 1) */ + __u64 r10; /* scratch (return value register 2) */ + __u64 r11; /* scratch (return value register 3) */ + + __u64 cr_ipsr; /* interrupted task's psr */ + __u64 cr_iip; /* interrupted task's instruction pointer */ + __u64 cr_ifs; /* interrupted task's function state */ + + __u64 ar_unat; /* interrupted task's NaT register (preserved) */ + __u64 ar_pfs; /* prev function state */ + __u64 ar_rsc; /* RSE configuration */ + /* The following two are valid only if cr_ipsr.cpl > 0: */ + __u64 ar_rnat; /* RSE NaT */ + __u64 ar_bspstore; /* RSE bspstore */ + + __u64 pr; /* 64 predicate registers (1 bit each) */ + __u64 b0; /* return pointer (bp) */ + __u64 loadrs; /* size of dirty partition << 16 */ + + __u64 r1; /* the gp pointer */ + __u64 r12; /* interrupted task's memory stack pointer */ + __u64 r13; /* thread pointer */ + + __u64 ar_fpsr; /* floating point status (preserved) */ + __u64 r15; /* scratch */ + + /* The remaining registers are NOT saved for system calls. */ + + __u64 r14; /* scratch */ + __u64 r2; /* scratch */ + __u64 r3; /* scratch */ + + /* The following registers are saved by SAVE_REST: */ + __u64 r16; /* scratch */ + __u64 r17; /* scratch */ + __u64 r18; /* scratch */ + __u64 r19; /* scratch */ + __u64 r20; /* scratch */ + __u64 r21; /* scratch */ + __u64 r22; /* scratch */ + __u64 r23; /* scratch */ + __u64 r24; /* scratch */ + __u64 r25; /* scratch */ + __u64 r26; /* scratch */ + __u64 r27; /* scratch */ + __u64 r28; /* scratch */ + __u64 r29; /* scratch */ + __u64 r30; /* scratch */ + __u64 r31; /* scratch */ + + __u64 ar_ccv; /* compare/exchange value (scratch) */ + + /* + * Floating point registers that the kernel considers scratch: + */ + struct _ia64_fpreg f6; /* scratch */ + struct _ia64_fpreg f7; /* scratch */ + struct _ia64_fpreg f8; /* scratch */ + struct _ia64_fpreg f9; /* scratch */ + struct _ia64_fpreg f10; /* scratch */ + struct _ia64_fpreg f11; /* scratch */ +}; + +#define ELF_NGREG_IA64 (sizeof (struct user_regs_struct_ia64) / sizeof(__u64)) +typedef __u64 elf_gregset_ia64_t[ELF_NGREG_IA64]; + +struct elf_prstatus_ia64 { + char pad[112]; + elf_gregset_ia64_t pr_reg; /* GP registers */ + __u32 pr_fpvalid; /* True if math co-processor being used. */ +}; + +union prstatus { + struct elf_prstatus_i386 x86; + struct elf_prstatus_x86_64 x86_64; + struct elf_prstatus_ppc64 ppc64; + struct elf_prstatus_ia64 ia64; +}; + +static size_t +dump_elf_note(char *buf, Elf64_Word type, char *name, char *desc, int d_len) +{ + Elf64_Nhdr *note; + size_t len; + + note = (Elf64_Nhdr *)buf; + note->n_namesz = strlen(name); + note->n_descsz = d_len; + note->n_type = type; + len = sizeof(Elf64_Nhdr); + + memcpy(buf + len, name, note->n_namesz); + len = roundup(len + note->n_namesz, 4); + + memcpy(buf + len, desc, note->n_descsz); + len = roundup(len + note->n_descsz, 4); + + return len; +} + +char * +generate_elf_header(int type, int fd, char *filename) +{ + int i, n; + char *buffer, *ptr; + Elf64_Ehdr *elf; + Elf64_Phdr *notes; + Elf64_Phdr *load; + size_t offset, len, l_offset; + size_t data_offset; + struct elf_prpsinfo_64 prpsinfo; + union prstatus prstatus; + int prstatus_len; + ushort e_machine; + int num_segments; + struct node_table *nt; + ulonglong task_struct; + + num_segments = vt->numnodes; + + if (machine_type("X86_64")) { + e_machine = EM_X86_64; + prstatus_len = sizeof(prstatus.x86_64); + num_segments += 1; /* mapped kernel section for phys_base */ + } else if (machine_type("X86")) { + e_machine = EM_386; + prstatus_len = sizeof(prstatus.x86); + } else if (machine_type("IA64")) { + e_machine = EM_IA_64; + prstatus_len = sizeof(prstatus.ia64); + num_segments += 1; /* mapped kernel section for phys_start */ + } else if (machine_type("PPC64")) { + e_machine = EM_PPC64; + prstatus_len = sizeof(prstatus.ppc64); + } else + return NULL; + + /* should be enought for the notes + roundup + two blocks */ + buffer = (char *)GETBUF(sizeof(Elf64_Ehdr) + + num_segments * sizeof(Elf64_Phdr) + PAGESIZE() * 2); + offset = 0; + ptr = buffer; + + /* Elf header */ + elf = (Elf64_Ehdr *)ptr; + memcpy(elf->e_ident, ELFMAG, SELFMAG); + elf->e_ident[EI_CLASS] = ELFCLASS64; +#if __BYTE_ORDER == __BIG_ENDIAN + elf->e_ident[EI_DATA] = ELFDATA2MSB; +#else + elf->e_ident[EI_DATA] = ELFDATA2LSB; +#endif + elf->e_ident[EI_VERSION] = EV_CURRENT; + elf->e_ident[EI_OSABI] = ELFOSABI_SYSV; + elf->e_ident[EI_ABIVERSION] = 0; + memset(elf->e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD); + + elf->e_type = ET_CORE; + elf->e_machine = e_machine; + elf->e_version = EV_CURRENT; + elf->e_entry = 0; + elf->e_phoff = sizeof(Elf64_Ehdr); + elf->e_shoff = 0; + elf->e_flags = 0; + elf->e_ehsize = sizeof(Elf64_Ehdr); + elf->e_phentsize = sizeof(Elf64_Phdr); + elf->e_phnum = 1 + num_segments; + elf->e_shentsize = 0; + elf->e_shnum = 0; + elf->e_shstrndx = 0; + + offset += sizeof(Elf64_Ehdr); + ptr += sizeof(Elf64_Ehdr); + + /* PT_NOTE */ + notes = (Elf64_Phdr *)ptr; + notes->p_type = PT_NOTE; + notes->p_offset = 0; /* TO BE FILLED IN */ + notes->p_vaddr = 0; + notes->p_paddr = 0; + notes->p_filesz = 0; /* TO BE FILLED IN */ + notes->p_memsz = 0; + notes->p_flags = 0; + notes->p_align = 0; + + offset += sizeof(Elf64_Phdr); + ptr += sizeof(Elf64_Phdr); + + /* PT_LOAD */ + load = (Elf64_Phdr *)ptr; + for (i = n = 0; i < num_segments; i++) { + load[i].p_type = PT_LOAD; + load[i].p_offset = 0; /* TO BE FILLED IN */ + + switch (e_machine) + { + case EM_X86_64: + nt = &vt->node_table[n]; + if (i == 0) { +#ifdef X86_64 + load[i].p_vaddr = __START_KERNEL_map; + load[i].p_paddr = machdep->machspec->phys_base; +#endif + load[i].p_filesz = 0; + load[i].p_memsz = load[i].p_filesz; + } else { + load[i].p_vaddr = PTOV(nt->start_paddr); + load[i].p_paddr = nt->start_paddr; + load[i].p_filesz = nt->size * PAGESIZE(); + load[i].p_memsz = load[i].p_filesz; + n++; + } + load[i].p_flags = PF_R | PF_W | PF_X; + load[i].p_align = 0; + break; + + case EM_386: + nt = &vt->node_table[n++]; + load[i].p_vaddr = 0; + load[i].p_paddr = nt->start_paddr; + load[i].p_filesz = nt->size * PAGESIZE(); + load[i].p_memsz = load[i].p_filesz; + load[i].p_flags = PF_R | PF_W | PF_X; + load[i].p_align = (type == NETDUMP_ELF64) ? PAGESIZE() : 0; + break; + + case EM_IA_64: + nt = &vt->node_table[n]; + if (i == 0) { +#ifdef IA64 + load[i].p_vaddr = machdep->machspec->kernel_start; + load[i].p_paddr = machdep->machspec->phys_start; +#endif + load[i].p_filesz = 0; + load[i].p_memsz = load[i].p_filesz; + } else { + load[i].p_vaddr = PTOV(nt->start_paddr); + load[i].p_paddr = nt->start_paddr; + load[i].p_filesz = nt->size * PAGESIZE(); + load[i].p_memsz = load[i].p_filesz; + n++; + } + load[i].p_flags = PF_R | PF_W | PF_X; + load[i].p_align = (type == NETDUMP_ELF64) ? PAGESIZE() : 0; + break; + + case EM_PPC64: + nt = &vt->node_table[n++]; + load[i].p_vaddr = PTOV(nt->start_paddr); + load[i].p_paddr = nt->start_paddr; + load[i].p_filesz = nt->size * PAGESIZE(); + load[i].p_memsz = load[i].p_filesz; + load[i].p_flags = PF_R | PF_W | PF_X; + load[i].p_align = (type == NETDUMP_ELF64) ? PAGESIZE() : 0; + break; + } + +// l_offset += load[i].p_filesz; + offset += sizeof(Elf64_Phdr); + ptr += sizeof(Elf64_Phdr); + } + notes->p_offset = offset; + + /* NT_PRSTATUS note */ + memset(&prstatus, 0, sizeof(prstatus)); + len = dump_elf_note(ptr, NT_PRSTATUS, "CORE", + (char *)&prstatus, prstatus_len); + offset += len; + ptr += len; + notes->p_filesz += len; + + /* NT_PRPSINFO note */ + memset(&prpsinfo, 0, sizeof(struct elf_prpsinfo_64)); + prpsinfo.pr_state = 0; + prpsinfo.pr_sname = 'R'; + prpsinfo.pr_zomb = 0; + strcpy(prpsinfo.pr_fname, "vmlinux"); + + len = dump_elf_note(ptr, NT_PRPSINFO, "CORE", + (char *)&prpsinfo, sizeof(prpsinfo)); + + offset += len; + ptr += len; + notes->p_filesz += len; + + /* NT_TASKSTRUCT note */ + task_struct = CURRENT_TASK(); + len = dump_elf_note (ptr, NT_TASKSTRUCT, "SNAP", + (char *)&task_struct, sizeof(ulonglong)); + offset += len; + ptr += len; + notes->p_filesz += len; + + if (type == NETDUMP_ELF64) + offset = roundup (offset, PAGESIZE()); + + l_offset = offset; + for (i = 0; i < num_segments; i++) { + load[i].p_offset = l_offset; + l_offset += load[i].p_filesz; + } + data_offset = offset; + + while (offset > 0) { + len = write(fd, buffer + (data_offset - offset), offset); + if (len < 0) { + perror(filename); + FREEBUF(buffer); + return NULL; + } + + offset -= len; + } + + return buffer; +} + +struct ram_segments { + physaddr_t start; + physaddr_t end; +}; + +static struct ram_segments *ram_segments = NULL; +static int nr_segments = 0; + +static void +init_ram_segments(void) +{ + int i, errflag; + FILE *iomem; + char buf[BUFSIZE], *p1, *p2; + physaddr_t start, end; + + if ((iomem = fopen("/proc/iomem", "r")) == NULL) + goto fail_iomem; + + while (fgets(buf, BUFSIZE, iomem)) { + if (strstr(buf, "System RAM")) { + console(buf); + nr_segments++; + } + } + if (!nr_segments) + goto fail_iomem; + + ram_segments = (struct ram_segments *) + GETBUF(sizeof(struct ram_segments) * nr_segments); + + rewind(iomem); + i = 0; + while (fgets(buf, BUFSIZE, iomem)) { + if (strstr(buf, "System RAM")) { + if (!(p1 = strstr(buf, ":"))) + goto fail_iomem; + *p1 = NULLCHAR; + clean_line(buf); + if (strstr(buf, " ")) + goto fail_iomem; + p1 = buf; + if (!(p2 = strstr(buf, "-"))) + goto fail_iomem; + *p2 = NULLCHAR; + p2++; + errflag = 0; + start = htoll(p1, RETURN_ON_ERROR|QUIET, &errflag); + end = htoll(p2, RETURN_ON_ERROR|QUIET, &errflag); + if (errflag) + goto fail_iomem; + ram_segments[i].start = PHYSPAGEBASE(start); + if (PAGEOFFSET(start)) + ram_segments[i].start += PAGESIZE(); + ram_segments[i].end = PHYSPAGEBASE(end); + if (PAGEOFFSET(end) == (PAGESIZE()-1)) + ram_segments[i].end += PAGESIZE(); + console("ram_segments[%d]: %016llx %016llx [%s-%s]\n", i, + (ulonglong)ram_segments[i].start, + (ulonglong)ram_segments[i].end, p1, p2); + i++; + } + } + + fclose(iomem); + return; + +fail_iomem: + fclose(iomem); + nr_segments = 0; + if (ram_segments) + FREEBUF(ram_segments); + + return; +} + +static int +verify_paddr(physaddr_t paddr) +{ + int i, ok; + + if (!machdep->verify_paddr(paddr)) + return FALSE; + + if (!nr_segments) + return TRUE; + + for (i = ok = 0; i < nr_segments; i++) { + if ((paddr >= ram_segments[i].start) && + (paddr < ram_segments[i].end)) { + ok++; + break; + } + } + + /* + * Pre-2.6.13 x86_64 /proc/iomem was restricted to 4GB, + * so just accept it. + */ + if ((paddr >= 0x100000000ULL) && + machine_type("X86_64") && + (THIS_KERNEL_VERSION < LINUX(2,6,13))) + ok++; + + if (!ok) { + if (CRASHDEBUG(1)) + console("reject: %llx\n", (ulonglong)paddr); + return FALSE; + } + + return TRUE; +} + +/* + * Borrowed from makedumpfile, prints a percentage-done value + * once per second. + */ +static int +print_progress(const char *filename, ulong current) +{ + int n, progress; + time_t tm; + struct node_table *nt; + static time_t last_time = 0; + static ulong total_pages = 0; + + if (!total_pages) { + for (n = 0; n < vt->numnodes; n++) { + nt = &vt->node_table[n]; + total_pages += nt->size; + } + } + + if (received_SIGINT()) { + fprintf(stderr, "\n\n"); + return FALSE; + } + + if (current < total_pages) { + tm = time(NULL); + if (tm - last_time < 1) + return TRUE; + last_time = tm; + progress = current * 100 / total_pages; + } else + progress = 100; + + fprintf(stderr, "\r%s: [%2d%%] ", filename, progress); + + return TRUE; +} diff --git a/extensions/snap.mk b/extensions/snap.mk new file mode 100644 index 00000000..d877e88e --- /dev/null +++ b/extensions/snap.mk @@ -0,0 +1,46 @@ +# +# Copyright (C) 2009, 2011, 2013 David Anderson +# Copyright (C) 2009, 2011, 2013 Red Hat, Inc. 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. +# + +ifeq ($(shell arch), i686) + TARGET=X86 + TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64 +endif +ifeq ($(shell arch), ppc64) + TARGET=PPC64 + TARGET_CFLAGS=-m64 +endif +ifeq ($(shell arch), ia64) + TARGET=IA64 + TARGET_CFLAGS= +endif +ifeq ($(shell arch), x86_64) + TARGET=X86_64 + TARGET_CFLAGS= +endif + +ifeq ($(shell /bin/ls /usr/include/crash/defs.h 2>/dev/null), /usr/include/crash/defs.h) + INCDIR=/usr/include/crash +endif +ifeq ($(shell /bin/ls ../defs.h 2> /dev/null), ../defs.h) + INCDIR=.. +endif +ifeq ($(shell /bin/ls ./defs.h 2> /dev/null), ./defs.h) + INCDIR=. +endif + +all: snap.so + +snap.so: $(INCDIR)/defs.h snap.c + gcc -Wall -I$(INCDIR) -shared -rdynamic -o snap.so snap.c -fPIC -D$(TARGET) $(TARGET_CFLAGS) $(GDB_FLAGS) diff --git a/extensions/trace.c b/extensions/trace.c new file mode 100644 index 00000000..a09f6a14 --- /dev/null +++ b/extensions/trace.c @@ -0,0 +1,2205 @@ +/* + * trace extension module for crash + * + * Copyright (C) 2009, 2010 FUJITSU LIMITED + * Author: Lai Jiangshan + * + * 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, or (at your option) + * any later version. + */ + +#define _GNU_SOURCE +#include "defs.h" +#include +#include +#include +#include + +static int verbose = 0; + +static int nr_cpu_ids; + +/* + * lockless ring_buffer and old non-lockless ring_buffer are both supported. + */ +static int lockless_ring_buffer; +static int per_cpu_buffer_sizes; +/* + * global and encapsulated current_trace are both supported + */ +static int encapsulated_current_trace; +/* + * trace_buffer is supported + */ +static int trace_buffer_available; + +#define koffset(struct, member) struct##_##member##_offset + +static int koffset(trace_array, current_trace); +static int koffset(trace_array, trace_buffer); +static int koffset(trace_array, max_buffer); +static int koffset(trace_buffer, buffer); +static int koffset(trace_array, buffer); +static int koffset(tracer, name); + +static int koffset(ring_buffer, pages); +static int koffset(ring_buffer, flags); +static int koffset(ring_buffer, cpus); +static int koffset(ring_buffer, buffers); + +static int koffset(ring_buffer_per_cpu, cpu); +static int koffset(ring_buffer_per_cpu, pages); +static int koffset(ring_buffer_per_cpu, nr_pages); +static int koffset(ring_buffer_per_cpu, head_page); +static int koffset(ring_buffer_per_cpu, tail_page); +static int koffset(ring_buffer_per_cpu, commit_page); +static int koffset(ring_buffer_per_cpu, reader_page); +static int koffset(ring_buffer_per_cpu, overrun); +static int koffset(ring_buffer_per_cpu, entries); + +static int koffset(buffer_page, read); +static int koffset(buffer_page, list); +static int koffset(buffer_page, page); + +static int koffset(list_head, next); + +static int koffset(ftrace_event_call, list); + +static int koffset(ftrace_event_field, link); +static int koffset(ftrace_event_field, name); +static int koffset(ftrace_event_field, type); +static int koffset(ftrace_event_field, offset); +static int koffset(ftrace_event_field, size); +static int koffset(ftrace_event_field, is_signed); + +static int koffset(POINTER_SYM, POINTER) = 0; + +struct ring_buffer_per_cpu { + ulong kaddr; + + ulong head_page; + ulong tail_page; + ulong commit_page; + ulong reader_page; + ulong real_head_page; + + int head_page_index; + unsigned int nr_pages; + ulong *pages; + + ulong *linear_pages; + int nr_linear_pages; + + ulong overrun; + ulong entries; +}; + +static ulong global_trace; +static ulong global_trace_buffer; +static ulong global_max_buffer; +static ulong global_ring_buffer; +static unsigned global_pages; +static struct ring_buffer_per_cpu *global_buffers; + +static ulong max_tr_trace; +static ulong max_tr_ring_buffer; +static unsigned max_tr_pages; +static struct ring_buffer_per_cpu *max_tr_buffers; + +static ulong ftrace_events; +static ulong current_trace; +static const char *current_tracer_name; + +static void ftrace_destroy_event_types(void); +static int ftrace_init_event_types(void); + +/* at = ((struct *)ptr)->member */ +#define read_value(at, ptr, struct, member) \ + do { \ + if (!readmem(ptr + koffset(struct, member), KVADDR, \ + &at, sizeof(at), #struct "'s " #member, \ + RETURN_ON_ERROR)) \ + goto out_fail;\ + } while (0) + +/* Remove the "const" qualifiers for ptr */ +#define free(ptr) free((void *)(ptr)) + +static int write_and_check(int fd, void *data, size_t size) +{ + size_t tot = 0; + size_t w; + + do { + w = write(fd, data, size - tot); + tot += w; + + if (w <= 0) + return -1; + } while (tot != size); + + return 0; +} + +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +static int init_offsets(void) +{ +#define init_offset(struct, member) do { \ + koffset(struct, member) = MEMBER_OFFSET(#struct, #member);\ + if (koffset(struct, member) < 0) { \ + fprintf(fp, "failed to init the offset, struct:"\ + #struct ", member:" #member); \ + return -1; \ + } \ + } while (0) + + if (encapsulated_current_trace) + init_offset(trace_array, current_trace); + + if (trace_buffer_available) { + init_offset(trace_array, trace_buffer); + init_offset(trace_array, max_buffer); + init_offset(trace_buffer, buffer); + } else { + init_offset(trace_array, buffer); + } + init_offset(tracer, name); + + if (MEMBER_EXISTS("ring_buffer_per_cpu", "nr_pages")) { + per_cpu_buffer_sizes = 1; + if (verbose) + fprintf(fp, "per cpu buffer sizes\n"); + } + + if (!per_cpu_buffer_sizes) + init_offset(ring_buffer, pages); + init_offset(ring_buffer, flags); + init_offset(ring_buffer, cpus); + init_offset(ring_buffer, buffers); + + if (MEMBER_SIZE("ring_buffer_per_cpu", "pages") == sizeof(ulong)) { + lockless_ring_buffer = 1; + if (verbose) + fprintf(fp, "lockless\n"); + } + + if (per_cpu_buffer_sizes) + init_offset(ring_buffer_per_cpu, nr_pages); + init_offset(ring_buffer_per_cpu, cpu); + init_offset(ring_buffer_per_cpu, pages); + init_offset(ring_buffer_per_cpu, head_page); + init_offset(ring_buffer_per_cpu, tail_page); + init_offset(ring_buffer_per_cpu, commit_page); + init_offset(ring_buffer_per_cpu, reader_page); + init_offset(ring_buffer_per_cpu, overrun); + init_offset(ring_buffer_per_cpu, entries); + + init_offset(buffer_page, read); + init_offset(buffer_page, list); + init_offset(buffer_page, page); + + init_offset(list_head, next); + + init_offset(ftrace_event_call, list); + + init_offset(ftrace_event_field, link); + init_offset(ftrace_event_field, name); + init_offset(ftrace_event_field, type); + init_offset(ftrace_event_field, offset); + init_offset(ftrace_event_field, size); + init_offset(ftrace_event_field, is_signed); + + return 0; +#undef init_offset +} + +static void print_offsets(void) +{ + if (!verbose) + return; + +#define print_offset(struct, member) fprintf(fp, \ + "koffset(" #struct ", " #member ") = %d\n", koffset(struct, member)) + + print_offset(trace_array, buffer); + print_offset(tracer, name); + + print_offset(ring_buffer, pages); + print_offset(ring_buffer, flags); + print_offset(ring_buffer, cpus); + print_offset(ring_buffer, buffers); + + print_offset(ring_buffer_per_cpu, cpu); + print_offset(ring_buffer_per_cpu, pages); + print_offset(ring_buffer_per_cpu, head_page); + print_offset(ring_buffer_per_cpu, tail_page); + print_offset(ring_buffer_per_cpu, commit_page); + print_offset(ring_buffer_per_cpu, reader_page); + print_offset(ring_buffer_per_cpu, overrun); + print_offset(ring_buffer_per_cpu, entries); + + print_offset(buffer_page, read); + print_offset(buffer_page, list); + print_offset(buffer_page, page); + + print_offset(list_head, next); + + print_offset(ftrace_event_call, list); + + print_offset(ftrace_event_field, link); + print_offset(ftrace_event_field, name); + print_offset(ftrace_event_field, type); + print_offset(ftrace_event_field, offset); + print_offset(ftrace_event_field, size); + print_offset(ftrace_event_field, is_signed); +#undef print_offset +} + +static int ftrace_init_pages(struct ring_buffer_per_cpu *cpu_buffer, + unsigned nr_pages) +{ + unsigned j = 0, count = 0; + ulong head, page; + ulong real_head_page = cpu_buffer->head_page; + + cpu_buffer->pages = calloc(sizeof(ulong), nr_pages); + if (cpu_buffer->pages == NULL) + return -1; + + cpu_buffer->linear_pages = calloc(sizeof(ulong), nr_pages + 1); + if (cpu_buffer->linear_pages == NULL) { + return -1; + } + + if (lockless_ring_buffer) { + read_value(head, cpu_buffer->kaddr, ring_buffer_per_cpu, pages); + cpu_buffer->pages[j++] = head - koffset(buffer_page, list); + } else + head = cpu_buffer->kaddr + koffset(ring_buffer_per_cpu, pages); + + page = head; + for (;;) { + read_value(page, page, list_head, next); + if (page & 3) { + /* lockless_ring_buffer */ + page &= ~3; + real_head_page = page - koffset(buffer_page, list); + } + + if (j == nr_pages) + break; + + if (page == head) { + error(INFO, "Num of pages is less than %d\n", nr_pages); + goto out_fail; + } + + cpu_buffer->pages[j++] = page - koffset(buffer_page, list); + } + + if (page != head) { + error(INFO, "Num of pages is larger than %d\n", nr_pages); + goto out_fail; + } + + /* find head page and head_page_index */ + + cpu_buffer->real_head_page = real_head_page; + cpu_buffer->head_page_index = -1; + + for (j = 0; j < nr_pages; j++) { + if (cpu_buffer->pages[j] == real_head_page) { + cpu_buffer->head_page_index = j; + break; + } + } + + if (cpu_buffer->head_page_index == -1) { + error(INFO, "error for resolve head_page_index\n"); + goto out_fail; + } + + /* Setup linear pages */ + + cpu_buffer->linear_pages[count++] = cpu_buffer->reader_page; + + if (cpu_buffer->reader_page == cpu_buffer->commit_page) + goto done; + + j = cpu_buffer->head_page_index; + for (;;) { + cpu_buffer->linear_pages[count++] = cpu_buffer->pages[j]; + + if (cpu_buffer->pages[j] == cpu_buffer->commit_page) + break; + + j++; + if (j == nr_pages) + j = 0; + + if (j == cpu_buffer->head_page_index) { + /* cpu_buffer->commit_page may be corrupted */ + break; + } + } + +done: + cpu_buffer->nr_linear_pages = count; + + return 0; + +out_fail: + return -1; +} + +static void ftrace_destroy_buffers(struct ring_buffer_per_cpu *buffers) +{ + int i; + + for (i = 0; i < nr_cpu_ids; i++) { + if (!buffers[i].kaddr) + continue; + + free(buffers[i].pages); + free(buffers[i].linear_pages); + } +} + +static int ftrace_init_buffers(struct ring_buffer_per_cpu *buffers, + ulong ring_buffer, unsigned pages) +{ + int i; + ulong buffers_array; + + read_value(buffers_array, ring_buffer, ring_buffer, buffers); + + for (i = 0; i < nr_cpu_ids; i++) { + if (!readmem(buffers_array + sizeof(ulong) * i, KVADDR, + &buffers[i].kaddr, sizeof(ulong), + "ring_buffer's cpu buffer", RETURN_ON_ERROR)) + goto out_fail; + + if (!buffers[i].kaddr) + continue; + +#define buffer_read_value(member) read_value(buffers[i].member, \ + buffers[i].kaddr, ring_buffer_per_cpu, member) + + buffer_read_value(head_page); + buffer_read_value(tail_page); + buffer_read_value(commit_page); + buffer_read_value(reader_page); + buffer_read_value(overrun); + buffer_read_value(entries); + if (per_cpu_buffer_sizes) { + buffer_read_value(nr_pages); + pages = buffers[i].nr_pages; + } else + buffers[i].nr_pages = pages; + +#undef buffer_read_value + + if (ftrace_init_pages(buffers + i, pages) < 0) + goto out_fail; + + if (verbose) { + fprintf(fp, "overrun=%lu\n", buffers[i].overrun); + fprintf(fp, "entries=%lu\n", buffers[i].entries); + } + } + + return 0; + +out_fail: + ftrace_destroy_buffers(buffers); + return -1; +} + +static int ftrace_int_global_trace(void) +{ + if (trace_buffer_available) { + global_trace_buffer = global_trace + koffset(trace_array, trace_buffer); + read_value(global_ring_buffer, global_trace_buffer, trace_buffer, buffer); + } else { + read_value(global_ring_buffer, global_trace, trace_array, buffer); + read_value(global_pages, global_ring_buffer, ring_buffer, pages); + } + + global_buffers = calloc(sizeof(*global_buffers), nr_cpu_ids); + if (global_buffers == NULL) + goto out_fail; + + if (ftrace_init_buffers(global_buffers, global_ring_buffer, + global_pages) < 0) + goto out_fail; + + return 0; + +out_fail: + free(global_buffers); + return -1; +} + +static int ftrace_int_max_tr_trace(void) +{ + if (trace_buffer_available) { + global_max_buffer = global_trace + koffset(trace_array, max_buffer); + read_value(max_tr_ring_buffer, global_max_buffer, trace_buffer, buffer); + } else { + read_value(max_tr_ring_buffer, max_tr_trace, trace_array, buffer); + + if (!max_tr_ring_buffer) + return 0; + + read_value(max_tr_pages, max_tr_ring_buffer, ring_buffer, pages); + } + + max_tr_buffers = calloc(sizeof(*max_tr_buffers), nr_cpu_ids); + if (max_tr_buffers == NULL) + goto out_fail; + + if (ftrace_init_buffers(max_tr_buffers, max_tr_ring_buffer, + max_tr_pages) < 0) + goto out_fail; + + return 0; + +out_fail: + free(max_tr_buffers); + max_tr_ring_buffer = 0; + return -1; +} + +static int ftrace_init_current_tracer(void) +{ + ulong addr; + char tmp[128]; + + /* Get current tracer name */ + if (encapsulated_current_trace) { + read_value(addr, global_trace, trace_array, current_trace); + } else { + read_value(addr, current_trace, POINTER_SYM, POINTER); + } + + read_value(addr, addr, tracer, name); + read_string(addr, tmp, 128); + + current_tracer_name = strdup(tmp); + if (current_tracer_name == NULL) + goto out_fail; + + return 0; + +out_fail: + return -1; +} + +static int ftrace_init(void) +{ + struct syment *sym_global_trace; + struct syment *sym_max_tr_trace; + struct syment *sym_ftrace_events; + struct syment *sym_current_trace; + + sym_global_trace = symbol_search("global_trace"); + sym_ftrace_events = symbol_search("ftrace_events"); + + if (sym_global_trace == NULL || sym_ftrace_events == NULL) + return -1; + + global_trace = sym_global_trace->value; + ftrace_events = sym_ftrace_events->value; + + if (MEMBER_EXISTS("trace_array", "current_trace")) { + encapsulated_current_trace = 1; + } else { + sym_current_trace = symbol_search("current_trace"); + if (sym_current_trace == NULL) + return -1; + + current_trace = sym_current_trace->value; + } + + if (MEMBER_EXISTS("trace_array", "trace_buffer")) { + trace_buffer_available = 1; + } else { + sym_max_tr_trace = symbol_search("max_tr"); + if (sym_max_tr_trace == NULL) + return -1; + + max_tr_trace = sym_max_tr_trace->value; + } + + if (!try_get_symbol_data("nr_cpu_ids", sizeof(int), &nr_cpu_ids)) + nr_cpu_ids = 1; + + if (init_offsets() < 0) + return -1; + print_offsets(); + + if (ftrace_int_global_trace() < 0) + goto out_0; + + ftrace_int_max_tr_trace(); + + if (ftrace_init_event_types() < 0) + goto out_1; + + if (ftrace_init_current_tracer() < 0) + goto out_2; + + return 0; + +out_2: + ftrace_destroy_event_types(); +out_1: + if (max_tr_ring_buffer) { + ftrace_destroy_buffers(max_tr_buffers); + free(max_tr_buffers); + } + ftrace_destroy_buffers(global_buffers); + free(global_buffers); +out_0: + return -1; +} + +static void ftrace_destroy(void) +{ + free(current_tracer_name); + ftrace_destroy_event_types(); + + if (max_tr_ring_buffer) { + ftrace_destroy_buffers(max_tr_buffers); + free(max_tr_buffers); + } + + ftrace_destroy_buffers(global_buffers); + free(global_buffers); +} + +static int ftrace_dump_page(int fd, ulong page, void *page_tmp) +{ + ulong raw_page; + + read_value(raw_page, page, buffer_page, page); + + if (!readmem(raw_page, KVADDR, page_tmp, PAGESIZE(), "get page context", + RETURN_ON_ERROR)) + goto out_fail; + + if (write_and_check(fd, page_tmp, PAGESIZE())) + return -1; + + return 0; + +out_fail: + return -1; +} + +static +void ftrace_dump_buffer(int fd, struct ring_buffer_per_cpu *cpu_buffer, + unsigned pages, void *page_tmp) +{ + int i; + + for (i = 0; i < cpu_buffer->nr_linear_pages; i++) { + if (ftrace_dump_page(fd, cpu_buffer->linear_pages[i], + page_tmp) < 0) + break; + } +} + +static int try_mkdir(const char *pathname, mode_t mode) +{ + int ret; + + ret = mkdir(pathname, mode); + if (ret < 0) { + if (errno == EEXIST) + return 0; + + error(INFO, "mkdir failed\n"); + return -1; + } + + return 0; +} + +static int ftrace_dump_buffers(const char *per_cpu_path) +{ + int i; + void *page_tmp; + char path[PATH_MAX]; + int fd; + + page_tmp = malloc(PAGESIZE()); + if (page_tmp == NULL) + return -1; + + for (i = 0; i < nr_cpu_ids; i++) { + struct ring_buffer_per_cpu *cpu_buffer = &global_buffers[i]; + + if (!cpu_buffer->kaddr) + continue; + + snprintf(path, sizeof(path), "%s/cpu%d", per_cpu_path, i); + if (try_mkdir(path, 0755) < 0) + goto out_fail; + + snprintf(path, sizeof(path), "%s/cpu%d/trace_pipe_raw", + per_cpu_path, i); + fd = open(path, O_WRONLY | O_CREAT, 0644); + if (fd < 0) + goto out_fail; + + ftrace_dump_buffer(fd, cpu_buffer, global_pages, page_tmp); + close(fd); + } + + free(page_tmp); + return 0; + +out_fail: + free(page_tmp); + return -1; +} + +#define MAX_CACHE_ID 256 + +struct ftrace_field { + const char *name; + const char *type; + int offset; + int size; + int is_signed; +}; + +struct event_type { + struct event_type *next; + const char *system; + const char *name; + int plugin; + const char *print_fmt; + int id; + int nfields; + struct ftrace_field *fields; +}; + +static struct event_type *event_type_cache[MAX_CACHE_ID]; +static struct event_type **event_types; +static int nr_event_types; + +static struct ftrace_field *ftrace_common_fields; +static int ftrace_common_fields_count; + +static int syscall_get_enter_fields(ulong call, ulong *fields) +{ + static int inited; + static int data_offset; + static int enter_fields_offset; + + ulong metadata; + + if (inited) + goto work; + + inited = 1; + data_offset = MEMBER_OFFSET("ftrace_event_call", "data"); + if (data_offset < 0) + return -1; + + enter_fields_offset = MEMBER_OFFSET("syscall_metadata", "enter_fields"); + if (enter_fields_offset < 0) + return -1; + +work: + if (data_offset < 0 || enter_fields_offset < 0) + return -1; + + if (!readmem(call + data_offset, KVADDR, &metadata, sizeof(metadata), + "read ftrace_event_call data", RETURN_ON_ERROR)) + return -1; + + *fields = metadata + enter_fields_offset; + return 0; +} + +static int syscall_get_exit_fields_old(ulong call, ulong *fields) +{ + static int inited; + static int data_offset; + static int exit_fields_offset; + + ulong metadata; + + if (inited) + goto work; + + inited = 1; + data_offset = MEMBER_OFFSET("ftrace_event_call", "data"); + if (data_offset < 0) + return -1; + + exit_fields_offset = MEMBER_OFFSET("syscall_metadata", "exit_fields"); + if (exit_fields_offset < 0) + return -1; + +work: + if (data_offset < 0 || exit_fields_offset < 0) + return -1; + + if (!readmem(call + data_offset, KVADDR, &metadata, sizeof(metadata), + "read ftrace_event_call data", RETURN_ON_ERROR)) + return -1; + + *fields = metadata + exit_fields_offset; + return 0; +} + +static int syscall_get_exit_fields(ulong call, ulong *fields) +{ + static int inited; + static ulong syscall_exit_fields_value; + + if (!inited) { + struct syment *sp; + + if (!(sp = symbol_search("syscall_exit_fields"))) { + inited = -1; + } else { + syscall_exit_fields_value = sp->value; + inited = 1; + } + } + + if (inited == -1) + return syscall_get_exit_fields_old(call, fields); + + *fields = syscall_exit_fields_value; + + return 0; +} + +static +int ftrace_get_event_type_fields(ulong call, ulong *fields) +{ + static int inited; + static int fields_offset; + static int class_offset; + static int get_fields_offset; + static ulong syscall_get_enter_fields_value; + static ulong syscall_get_exit_fields_value; + + struct syment *sp; + ulong class, get_fields; + + if (inited) + goto work; + + inited = 1; + fields_offset = MEMBER_OFFSET("ftrace_event_call", "fields"); + + class_offset = MEMBER_OFFSET("ftrace_event_call", "class"); + if (class_offset < 0) + goto work; + + inited = 2; + fields_offset = MEMBER_OFFSET("ftrace_event_class", "fields"); + if (fields_offset < 0) + return -1; + + get_fields_offset = MEMBER_OFFSET("ftrace_event_class", "get_fields"); + if ((sp = symbol_search("syscall_get_enter_fields")) != NULL) + syscall_get_enter_fields_value = sp->value; + if ((sp = symbol_search("syscall_get_exit_fields")) != NULL) + syscall_get_exit_fields_value = sp->value; + +work: + if (fields_offset < 0) + return -1; + + if (inited == 1) { + *fields = call + fields_offset; + return 0; + } + + if (!readmem(call + class_offset, KVADDR, &class, sizeof(class), + "read ftrace_event_call class", RETURN_ON_ERROR)) + return -1; + + if (!readmem(class + get_fields_offset, KVADDR, &get_fields, + sizeof(get_fields), "read ftrace_event_call get_fields", + RETURN_ON_ERROR)) + return -1; + + if (!get_fields) { + *fields = class + fields_offset; + return 0; + } + + if (get_fields == syscall_get_enter_fields_value) + return syscall_get_enter_fields(call, fields); + + if (get_fields == syscall_get_exit_fields_value) + return syscall_get_exit_fields(call, fields); + + fprintf(fp, "Unkown get_fields function\n"); + return -1; +} + +static int ftrace_init_event_fields(ulong fields_head, int *pnfields, + struct ftrace_field **pfields) +{ + ulong pos; + + int nfields = 0, max_fields = 16; + struct ftrace_field *fields = NULL; + + read_value(pos, fields_head, list_head, next); + + if (pos == 0) { + if (verbose) + fprintf(fp, "no field, head: %lu\n", fields_head); + return 0; + } + + fields = malloc(sizeof(*fields) * max_fields); + if (fields == NULL) + return -1; + + while (pos != fields_head) { + ulong field; + ulong name_addr, type_addr; + char field_name[128], field_type[128]; + int offset, size, is_signed; + + field = pos - koffset(ftrace_event_field, link); + + /* Read a field from the core */ + read_value(name_addr, field, ftrace_event_field, name); + read_value(type_addr, field, ftrace_event_field, type); + read_value(offset, field, ftrace_event_field, offset); + read_value(size, field, ftrace_event_field, size); + read_value(is_signed, field, ftrace_event_field, is_signed); + + if (!read_string(name_addr, field_name, 128)) + goto out_fail; + if (!read_string(type_addr, field_type, 128)) + goto out_fail; + + /* Enlarge fields array when need */ + if (nfields >= max_fields) { + void *tmp; + + max_fields = nfields * 2; + tmp = realloc(fields, sizeof(*fields) * max_fields); + if (tmp == NULL) + goto out_fail; + + fields = tmp; + } + + /* Set up and Add a field */ + fields[nfields].offset = offset; + fields[nfields].size = size; + fields[nfields].is_signed = is_signed; + + fields[nfields].name = strdup(field_name); + if (fields[nfields].name == NULL) + goto out_fail; + + fields[nfields].type = strdup(field_type); + if (fields[nfields].type == NULL) { + free(fields[nfields].name); + goto out_fail; + } + + nfields++; + + /* Advance to the next field */ + read_value(pos, pos, list_head, next); + } + + *pnfields = nfields; + *pfields = fields; + + return 0; + +out_fail: + for (nfields--; nfields >= 0; nfields--) { + free(fields[nfields].name); + free(fields[nfields].type); + } + + free(fields); + return -1; +} + +static int ftrace_init_event_type(ulong call, struct event_type *aevent_type) +{ + ulong fields_head = 0; + + if (ftrace_get_event_type_fields(call, &fields_head) < 0) + return -1; + + return ftrace_init_event_fields(fields_head, &aevent_type->nfields, + &aevent_type->fields); +} + +static int ftrace_init_common_fields(void) +{ + ulong ftrace_common_fields_head; + struct syment *sp; + + sp = symbol_search("ftrace_common_fields"); + if (!sp) + return 0; + + ftrace_common_fields_head = sp->value; + + return ftrace_init_event_fields(ftrace_common_fields_head, + &ftrace_common_fields_count, &ftrace_common_fields); +} + +static void ftrace_destroy_event_types(void) +{ + int i, j; + + for (i = 0; i < nr_event_types; i++) { + for (j = 0; j < event_types[i]->nfields; j++) { + free(event_types[i]->fields[j].name); + free(event_types[i]->fields[j].type); + } + + free(event_types[i]->fields); + free(event_types[i]->system); + free(event_types[i]->name); + free(event_types[i]->print_fmt); + free(event_types[i]); + } + + free(event_types); + free(ftrace_common_fields); +} + +static +int ftrace_get_event_type_name(ulong call, char *name, int len) +{ + static int inited; + static int name_offset; + + ulong name_addr; + + if (!inited) { + inited = 1; + name_offset = MEMBER_OFFSET("ftrace_event_call", "name"); + } + + if (name_offset < 0) + return -1; + + if (!readmem(call + name_offset, KVADDR, &name_addr, sizeof(name_addr), + "read ftrace_event_call name_addr", RETURN_ON_ERROR)) + return -1; + + if (!read_string(name_addr, name, len)) + return -1; + + return 0; +} + +static +int ftrace_get_event_type_system(ulong call, char *system, int len) +{ + static int inited; + static int sys_offset; + static int class_offset; + + ulong ptr = call; + ulong sys_addr; + + if (inited) + goto work; + + inited = 1; + sys_offset = MEMBER_OFFSET("ftrace_event_call", "system"); + + if (sys_offset >= 0) + goto work; + + class_offset = MEMBER_OFFSET("ftrace_event_call", "class"); + if (class_offset < 0) + return -1; + + sys_offset = MEMBER_OFFSET("ftrace_event_class", "system"); + inited = 2; + +work: + if (sys_offset < 0) + return -1; + + if (inited == 2 && !readmem(call + class_offset, KVADDR, &ptr, + sizeof(ptr), "read ftrace_event_call class_addr", + RETURN_ON_ERROR)) + return -1; + + if (!readmem(ptr + sys_offset, KVADDR, &sys_addr, sizeof(sys_addr), + "read ftrace_event_call sys_addr", RETURN_ON_ERROR)) + return -1; + + if (!read_string(sys_addr, system, len)) + return -1; + + return 0; +} + +static int read_long_string(ulong kvaddr, char **buf) +{ + char strbuf[MIN_PAGE_SIZE], *ret_buf = NULL; + ulong kp; + int cnt1, cnt2, size; + +again: + kp = kvaddr; + size = 0; + + for (;;) { + cnt1 = MIN_PAGE_SIZE - (kp & (MIN_PAGE_SIZE-1)); + + if (!readmem(kp, KVADDR, strbuf, cnt1, + "readstring characters", QUIET|RETURN_ON_ERROR)) + return -1; + + cnt2 = strnlen(strbuf, cnt1); + if (ret_buf) + memcpy(ret_buf + size, strbuf, cnt2); + kp += cnt2; + size += cnt2; + + if (cnt2 < cnt1) { + if (ret_buf) { + break; + } else { + ret_buf = malloc(size + 1); + if (!ret_buf) + return -1; + goto again; + } + } + } + + ret_buf[size] = '\0'; + *buf = ret_buf; + return size; +} + +static +int ftrace_get_event_type_print_fmt(ulong call, char **print_fmt) +{ + static int inited; + static int fmt_offset; + + ulong fmt_addr; + + if (!inited) { + inited = 1; + fmt_offset = MEMBER_OFFSET("ftrace_event_call", "print_fmt"); + } + + if (fmt_offset < 0) { + *print_fmt = strdup("Unknown print_fmt"); + return 0; + } + + if (!readmem(call + fmt_offset, KVADDR, &fmt_addr, sizeof(fmt_addr), + "read ftrace_event_call fmt_addr", RETURN_ON_ERROR)) + return -1; + + return read_long_string(fmt_addr, print_fmt); +} + +static +int ftrace_get_event_type_id(ulong call, int *id) +{ + static int inited; + static int id_offset; + + if (!inited) { + inited = 1; + id_offset = MEMBER_OFFSET("ftrace_event_call", "id"); + + if (id_offset < 0) { + /* id = call->event.type */ + int f1 = MEMBER_OFFSET("ftrace_event_call", "event"); + int f2 = MEMBER_OFFSET("trace_event", "type"); + + if (f1 >= 0 && f2 >= 0) + id_offset = f1 + f2; + } + } + + if (id_offset < 0) + return -1; + + if (!readmem(call + id_offset, KVADDR, id, sizeof(*id), + "read ftrace_event_call id", RETURN_ON_ERROR)) + return -1; + + return 0; +} + +static int ftrace_init_event_types(void) +{ + ulong event; + struct event_type *aevent_type; + int max_types = 128; + + event_types = malloc(sizeof(*event_types) * max_types); + if (event_types == NULL) + return -1; + + read_value(event, ftrace_events, list_head, next); + while (event != ftrace_events) { + ulong call; + char name[128], system[128], *print_fmt; + int id; + + call = event - koffset(ftrace_event_call, list); + + /* Read a event type from the core */ + if (ftrace_get_event_type_id(call, &id) < 0 || + ftrace_get_event_type_name(call, name, 128) < 0 || + ftrace_get_event_type_system(call, system, 128) < 0 || + ftrace_get_event_type_print_fmt(call, &print_fmt) < 0) + goto out_fail; + + /* Enlarge event types array when need */ + if (nr_event_types >= max_types) { + void *tmp; + + max_types = 2 * nr_event_types; + tmp = realloc(event_types, + sizeof(*event_types) * max_types); + if (tmp == NULL) { + free(print_fmt); + goto out_fail; + } + + event_types = tmp; + } + + /* Create a event type */ + aevent_type = malloc(sizeof(*aevent_type)); + if (aevent_type == NULL) { + free(print_fmt); + goto out_fail; + } + + aevent_type->system = strdup(system); + aevent_type->name = strdup(name); + aevent_type->print_fmt = print_fmt; + aevent_type->id = id; + aevent_type->nfields = 0; + aevent_type->fields = NULL; + + if (aevent_type->system == NULL || aevent_type->name == NULL) + goto out_fail_free_aevent_type; + + if (ftrace_init_event_type(call, aevent_type) < 0) + goto out_fail_free_aevent_type; + + if (!strcmp("ftrace", aevent_type->system)) + aevent_type->plugin = 1; + else + aevent_type->plugin = 0; + + /* Add a event type */ + event_types[nr_event_types++] = aevent_type; + if ((unsigned)id < MAX_CACHE_ID) + event_type_cache[id] = aevent_type; + + /* Advance to the next event type */ + read_value(event, event, list_head, next); + } + + if (ftrace_init_common_fields() < 0) + goto out_fail; + + return 0; + +out_fail_free_aevent_type: + free(aevent_type->system); + free(aevent_type->name); + free(aevent_type->print_fmt); + free(aevent_type); +out_fail: + ftrace_destroy_event_types(); + return -1; +} + +#define default_common_field_count 5 + +static int ftrace_dump_event_type(struct event_type *t, const char *path) +{ + char format_path[PATH_MAX]; + FILE *out; + int i, nfields; + struct ftrace_field *fields; + int printed_common_field = 0; + + snprintf(format_path, sizeof(format_path), "%s/format", path); + out = fopen(format_path, "w"); + if (out == NULL) + return -1; + + fprintf(out, "name: %s\n", t->name); + fprintf(out, "ID: %d\n", t->id); + fprintf(out, "format:\n"); + + if (ftrace_common_fields_count) { + nfields = ftrace_common_fields_count; + fields = ftrace_common_fields; + } else { + nfields = default_common_field_count; + fields = &t->fields[t->nfields - nfields]; + } + +again: + for (i = nfields - 1; i >= 0; i--) { + /* + * Smartly shows the array type(except dynamic array). + * Normal: + * field:TYPE VAR + * If TYPE := TYPE[LEN], it is shown: + * field:TYPE VAR[LEN] + */ + struct ftrace_field *field = &fields[i]; + const char *array_descriptor = strchr(field->type, '['); + + if (!strncmp(field->type, "__data_loc", 10)) + array_descriptor = NULL; + + if (!array_descriptor) { + fprintf(out, "\tfield:%s %s;\toffset:%u;" + "\tsize:%u;\tsigned:%d;\n", + field->type, field->name, field->offset, + field->size, !!field->is_signed); + } else { + fprintf(out, "\tfield:%.*s %s%s;\toffset:%u;" + "\tsize:%u;\tsigned:%d;\n", + (int)(array_descriptor - field->type), + field->type, field->name, + array_descriptor, field->offset, + field->size, !!field->is_signed); + } + } + + if (!printed_common_field) { + fprintf(out, "\n"); + + if (ftrace_common_fields_count) + nfields = t->nfields; + else + nfields = t->nfields - default_common_field_count; + fields = t->fields; + + printed_common_field = 1; + goto again; + } + + fprintf(out, "\nprint fmt: %s\n", t->print_fmt); + + fclose(out); + + return 0; +} + +static int ftrace_dump_event_types(const char *events_path) +{ + int i; + + for (i = 0; i < nr_event_types; i++) { + char path[PATH_MAX]; + struct event_type *t = event_types[i]; + + snprintf(path, sizeof(path), "%s/%s", events_path, t->system); + if (try_mkdir(path, 0755) < 0) + return -1; + + snprintf(path, sizeof(path), "%s/%s/%s", events_path, + t->system, t->name); + if (try_mkdir(path, 0755) < 0) + return -1; + + if (ftrace_dump_event_type(t, path) < 0) + return -1; + } + + return 0; +} + +static void show_basic_info(void) +{ + fprintf(fp, "current tracer is %s\n", current_tracer_name); +} + +static int dump_saved_cmdlines(const char *dump_tracing_dir) +{ + char path[PATH_MAX]; + FILE *out; + int i; + struct task_context *tc; + + snprintf(path, sizeof(path), "%s/saved_cmdlines", dump_tracing_dir); + out = fopen(path, "w"); + if (out == NULL) + return -1; + + tc = FIRST_CONTEXT(); + for (i = 0; i < RUNNING_TASKS(); i++) + fprintf(out, "%d %s\n", (int)tc[i].pid, tc[i].comm); + + fclose(out); + return 0; +} + +static int dump_kallsyms(const char *dump_tracing_dir) +{ + char path[PATH_MAX]; + FILE *out; + int i; + struct syment *sp; + + snprintf(path, sizeof(path), "%s/kallsyms", dump_tracing_dir); + out = fopen(path, "w"); + if (out == NULL) + return -1; + + for (sp = st->symtable; sp < st->symend; sp++) + fprintf(out, "%lx %c %s\n", sp->value, sp->type, sp->name); + + for (i = 0; i < st->mods_installed; i++) { + struct load_module *lm = &st->load_modules[i]; + + for (sp = lm->mod_symtable; sp <= lm->mod_symend; sp++) { + if (!strncmp(sp->name, "_MODULE_", strlen("_MODULE_"))) + continue; + + fprintf(out, "%lx %c %s\t[%s]\n", sp->value, sp->type, + sp->name, lm->mod_name); + } + } + + fclose(out); + return 0; +} + +static int trace_cmd_data_output(int fd); + +static void ftrace_dump(int argc, char *argv[]) +{ + int c; + int dump_meta_data = 0; + int dump_symbols = 0; + char *dump_tracing_dir; + char path[PATH_MAX]; + int ret; + + while ((c = getopt(argc, argv, "smt")) != EOF) { + switch(c) + { + case 's': + dump_symbols = 1; + break; + case 'm': + dump_meta_data = 1; + break; + case 't': + if (dump_symbols || dump_meta_data || argc - optind > 1) + cmd_usage(pc->curcmd, SYNOPSIS); + else { + char *trace_dat = "trace.dat"; + int fd; + + if (argc - optind == 0) + trace_dat = "trace.dat"; + else if (argc - optind == 1) + trace_dat = argv[optind]; + fd = open(trace_dat, O_WRONLY | O_CREAT + | O_TRUNC, 0644); + trace_cmd_data_output(fd); + close(fd); + } + return; + default: + cmd_usage(pc->curcmd, SYNOPSIS); + return; + } + } + + if (argc - optind == 0) { + dump_tracing_dir = "dump_tracing_dir"; + } else if (argc - optind == 1) { + dump_tracing_dir = argv[optind]; + } else { + cmd_usage(pc->curcmd, SYNOPSIS); + return; + } + + ret = mkdir(dump_tracing_dir, 0755); + if (ret < 0) { + if (errno == EEXIST) + error(INFO, "mkdir: %s exists\n", dump_tracing_dir); + return; + } + + snprintf(path, sizeof(path), "%s/per_cpu", dump_tracing_dir); + if (try_mkdir(path, 0755) < 0) + return; + + if (ftrace_dump_buffers(path) < 0) + return; + + if (dump_meta_data) { + /* Dump event types */ + snprintf(path, sizeof(path), "%s/events", dump_tracing_dir); + if (try_mkdir(path, 0755) < 0) + return; + + if (ftrace_dump_event_types(path) < 0) + return; + + /* Dump pids with corresponding cmdlines */ + if (dump_saved_cmdlines(dump_tracing_dir) < 0) + return; + } + + if (dump_symbols) { + /* Dump all symbols of the kernel */ + dump_kallsyms(dump_tracing_dir); + } +} + +static void ftrace_show(int argc, char *argv[]) +{ + char buf[4096]; + char tmp[] = "/tmp/crash.trace_dat.XXXXXX"; + char *trace_cmd = "trace-cmd", *env_trace_cmd = getenv("TRACE_CMD"); + int fd; + FILE *file; + size_t ret; + size_t nitems __attribute__ ((__unused__)); + char *unused __attribute__ ((__unused__)); + + /* check trace-cmd */ + if (env_trace_cmd) + trace_cmd = env_trace_cmd; + buf[0] = 0; + if ((file = popen(trace_cmd, "r"))) { + ret = fread(buf, 1, sizeof(buf), file); + buf[ret] = 0; + pclose(file); + } + if (!strstr(buf, "trace-cmd version")) { + if (env_trace_cmd) + fprintf(fp, "Invalid environment TRACE_CMD: %s\n", + env_trace_cmd); + else + fprintf(fp, "\"trace show\" requires trace-cmd.\n" + "please set the environment TRACE_CMD " + "if you installed it in a special path\n" + ); + return; + } + + /* dump trace.dat to the temp file */ + unused = mktemp(tmp); + fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if (trace_cmd_data_output(fd) < 0) + goto out; + + /* splice the output of trace-cmd to user */ + snprintf(buf, sizeof(buf), "%s report %s", trace_cmd, tmp); + if (!(file = popen(buf, "r"))) + goto out; + for (;;) { + ret = fread(buf, 1, sizeof(buf), file); + if (ret == 0) + break; + nitems = fwrite(buf, 1, ret, fp); + } + pclose(file); +out: + close(fd); + unlink(tmp); + return; +} + +static void cmd_ftrace(void) +{ + if (argcnt == 1) + show_basic_info(); + else if (!strcmp(args[1], "dump")) + ftrace_dump(argcnt - 1, args + 1); + else if (!strcmp(args[1], "show")) + ftrace_show(argcnt - 1, args + 1); + else if (!strcmp(args[1], "report")) + ftrace_show(argcnt - 1, args + 1); + else + cmd_usage(pc->curcmd, SYNOPSIS); +} + +static char *help_ftrace[] = { +"trace", +"show or dump the tracing info", +"[ ] [-f [no]]> | > ]", +"trace", +" shows the current tracer and other informations.", +"", +"trace show", +" shows all events with readability text(sorted by timestamp)", +"", +"trace report", +" the same as \"trace show\"", +"", +"trace dump [-sm] ", +" dump ring_buffers to dest-dir. Then you can parse it", +" by other tracing tools. The dirs and files are generated", +" the same as debugfs/tracing.", +" -m: also dump metadata of ftrace.", +" -s: also dump symbols of the kernel.", +"trace dump -t [output-file-name]", +" dump ring_buffers and all meta data to a file that can", +" be parsed by trace-cmd. Default output file name is \"trace.dat\".", +NULL +}; + +static struct command_table_entry command_table[] = { + { "trace", cmd_ftrace, help_ftrace, 0 }, + { NULL, 0, 0, 0 } +}; + +static int ftrace_initialized; + +void __attribute__((constructor)) +trace_init(void) +{ + if (ftrace_init() < 0) + return; + + ftrace_initialized = 1; + register_extension(command_table); +} + +void __attribute__((destructor)) +trace_fini(void) +{ + if (ftrace_initialized) + ftrace_destroy(); +} + +#define TRACE_CMD_FILE_VERSION_STRING "6" + +static inline int host_bigendian(void) +{ + unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 }; + unsigned int *ptr; + + ptr = (unsigned int *)str; + return *ptr == 0x01020304; +} + +static char *tmp_file_buf; +static unsigned long long tmp_file_pos; +static unsigned long long tmp_file_size; +static int tmp_file_error; + +static int init_tmp_file(void) +{ + tmp_file_buf = malloc(4096); + if (tmp_file_buf == NULL) + return -1; + + tmp_file_pos = 0; + tmp_file_size = 4096; + tmp_file_error = 0; + + return 0; +} + +static void destory_tmp_file(void) +{ + free(tmp_file_buf); +} + +#define tmp_fprintf(fmt...) \ +do { \ + char *__buf = tmp_file_buf; \ + unsigned long long __pos; \ + \ + if (tmp_file_error) \ + break; \ + __pos = tmp_file_pos; \ + __pos += snprintf(__buf + __pos, tmp_file_size - __pos, fmt); \ + if (__pos >= tmp_file_size) { \ + tmp_file_size = __pos + tmp_file_size; \ + __buf = realloc(__buf, tmp_file_size); \ + if (!__buf) { \ + tmp_file_error = 1; \ + break; \ + } \ + tmp_file_buf = __buf; \ + __pos = tmp_file_pos; \ + __pos += snprintf(__buf + __pos, tmp_file_size - __pos, fmt);\ + } \ + tmp_file_pos = __pos; \ +} while (0) + +static int tmp_file_record_size4(int fd) +{ + unsigned int size = tmp_file_pos; + + if (tmp_file_error) + return -1; + if (write_and_check(fd, &size, 4)) + return -1; + return 0; +} + +static int tmp_file_record_size8(int fd) +{ + if (tmp_file_error) + return -1; + if (write_and_check(fd, &tmp_file_pos, 8)) + return -1; + return 0; +} + +static int tmp_file_flush(int fd) +{ + if (tmp_file_error) + return -1; + if (write_and_check(fd, tmp_file_buf, tmp_file_pos)) + return -1; + tmp_file_pos = 0; + return 0; +} + +static int save_initial_data(int fd) +{ + int page_size; + char buf[20]; + + if (write_and_check(fd, "\027\010\104tracing", 10)) + return -1; + + if (write_and_check(fd, TRACE_CMD_FILE_VERSION_STRING, + strlen(TRACE_CMD_FILE_VERSION_STRING) + 1)) + return -1; + + /* Crash ensure core file endian and the host endian are the same */ + if (host_bigendian()) + buf[0] = 1; + else + buf[0] = 0; + + if (write_and_check(fd, buf, 1)) + return -1; + + /* save size of long (this may not be what the kernel is) */ + buf[0] = sizeof(long); + if (write_and_check(fd, buf, 1)) + return -1; + + page_size = PAGESIZE(); + if (write_and_check(fd, &page_size, 4)) + return -1; + + return 0; +} + +static int save_header_files(int fd) +{ + /* save header_page */ + if (write_and_check(fd, "header_page", 12)) + return -1; + + tmp_fprintf("\tfield: u64 timestamp;\toffset:0;\tsize:8;\tsigned:0;\n"); + + tmp_fprintf("\tfield: local_t commit;\toffset:8;\tsize:%u;\t" + "signed:1;\n", (unsigned int)sizeof(long)); + + tmp_fprintf("\tfield: int overwrite;\toffset:8;\tsize:%u;\tsigned:1;\n", + (unsigned int)sizeof(long)); + + tmp_fprintf("\tfield: char data;\toffset:%u;\tsize:%u;\tsigned:1;\n", + (unsigned int)(8 + sizeof(long)), + (unsigned int)(PAGESIZE() - 8 - sizeof(long))); + + if (tmp_file_record_size8(fd)) + return -1; + if (tmp_file_flush(fd)) + return -1; + + /* save header_event */ + if (write_and_check(fd, "header_event", 13)) + return -1; + + tmp_fprintf( + "# compressed entry header\n" + "\ttype_len : 5 bits\n" + "\ttime_delta : 27 bits\n" + "\tarray : 32 bits\n" + "\n" + "\tpadding : type == 29\n" + "\ttime_extend : type == 30\n" + "\tdata max type_len == 28\n" + ); + + if (tmp_file_record_size8(fd)) + return -1; + if (tmp_file_flush(fd)) + return -1; + + return 0; +} + +static int save_event_file(int fd, struct event_type *t) +{ + int i, nfields; + struct ftrace_field *fields; + int printed_common_field = 0; + + tmp_fprintf("name: %s\n", t->name); + tmp_fprintf("ID: %d\n", t->id); + tmp_fprintf("format:\n"); + + if (ftrace_common_fields_count) { + nfields = ftrace_common_fields_count; + fields = ftrace_common_fields; + } else { + nfields = default_common_field_count; + fields = &t->fields[t->nfields - nfields]; + } + +again: + for (i = nfields - 1; i >= 0; i--) { + /* + * Smartly shows the array type(except dynamic array). + * Normal: + * field:TYPE VAR + * If TYPE := TYPE[LEN], it is shown: + * field:TYPE VAR[LEN] + */ + struct ftrace_field *field = &fields[i]; + const char *array_descriptor = strchr(field->type, '['); + + if (!strncmp(field->type, "__data_loc", 10)) + array_descriptor = NULL; + + if (!array_descriptor) { + tmp_fprintf("\tfield:%s %s;\toffset:%u;" + "\tsize:%u;\tsigned:%d;\n", + field->type, field->name, field->offset, + field->size, !!field->is_signed); + } else { + tmp_fprintf("\tfield:%.*s %s%s;\toffset:%u;" + "\tsize:%u;\tsigned:%d;\n", + (int)(array_descriptor - field->type), + field->type, field->name, + array_descriptor, field->offset, + field->size, !!field->is_signed); + } + } + + if (!printed_common_field) { + tmp_fprintf("\n"); + + if (ftrace_common_fields_count) + nfields = t->nfields; + else + nfields = t->nfields - default_common_field_count; + fields = t->fields; + + printed_common_field = 1; + goto again; + } + + tmp_fprintf("\nprint fmt: %s\n", t->print_fmt); + + if (tmp_file_record_size8(fd)) + return -1; + return tmp_file_flush(fd); +} + +static int save_system_files(int fd, int *system_ids, int system_id) +{ + int i, total = 0; + + for (i = 0; i < nr_event_types; i++) { + if (system_ids[i] == system_id) + total++; + } + + if (write_and_check(fd, &total, 4)) + return -1; + + for (i = 0; i < nr_event_types; i++) { + if (system_ids[i] != system_id) + continue; + + if (save_event_file(fd, event_types[i])) + return -1; + } + + return 0; +} + +static int save_events_files(int fd) +{ + int system_id = 1, *system_ids; + const char *system = "ftrace"; + int i; + int nr_systems; + + system_ids = calloc(sizeof(*system_ids), nr_event_types); + if (system_ids == NULL) + return -1; + + for (;;) { + for (i = 0; i < nr_event_types; i++) { + if (system_ids[i]) + continue; + if (!system) { + system = event_types[i]->system; + system_ids[i] = system_id; + continue; + } + if (!strcmp(event_types[i]->system, system)) + system_ids[i] = system_id; + } + if (!system) + break; + system_id++; + system = NULL; + } + + /* ftrace events */ + if (save_system_files(fd, system_ids, 1)) + goto fail; + + /* other systems events */ + nr_systems = system_id - 2; + if (write_and_check(fd, &nr_systems, 4)) + goto fail; + for (system_id = 2; system_id < nr_systems + 2; system_id++) { + for (i = 0; i < nr_event_types; i++) { + if (system_ids[i] == system_id) + break; + } + if (write_and_check(fd, (void *)event_types[i]->system, + strlen(event_types[i]->system) + 1)) + goto fail; + if (save_system_files(fd, system_ids, system_id)) + goto fail; + } + + free(system_ids); + return 0; + +fail: + free(system_ids); + return -1; +} + +static int save_proc_kallsyms(int fd) +{ + int i; + struct syment *sp; + + for (sp = st->symtable; sp < st->symend; sp++) + tmp_fprintf("%lx %c %s\n", sp->value, sp->type, sp->name); + + for (i = 0; i < st->mods_installed; i++) { + struct load_module *lm = &st->load_modules[i]; + + for (sp = lm->mod_symtable; sp <= lm->mod_symend; sp++) { + if (!strncmp(sp->name, "_MODULE_", strlen("_MODULE_"))) + continue; + + tmp_fprintf("%lx %c %s\t[%s]\n", sp->value, sp->type, + sp->name, lm->mod_name); + } + } + + if (tmp_file_record_size4(fd)) + return -1; + return tmp_file_flush(fd); +} + +static int add_print_address(long address) +{ + char string[4096]; + size_t len; + int i; + + len = read_string(address, string, sizeof(string)); + if (!len) + return -1; + + tmp_fprintf("0x%lx : \"", address); + + for (i = 0; string[i]; i++) { + switch (string[i]) { + case '\n': + tmp_fprintf("\\n"); + break; + case '\t': + tmp_fprintf("\\t"); + break; + case '\\': + tmp_fprintf("\\\\"); + break; + case '"': + tmp_fprintf("\\\""); + break; + default: + tmp_fprintf("%c", string[i]); + } + } + tmp_fprintf("\"\n"); + + return 0; +} + +static int save_ftrace_printk(int fd) +{ + struct kernel_list_head *mod_fmt; + struct syment *s, *e, *b; + long bprintk_fmt_s, bprintk_fmt_e; + long *address; + size_t i, count; + int addr_is_array = 0; + + s = symbol_search("__start___trace_bprintk_fmt"); + e = symbol_search("__stop___trace_bprintk_fmt"); + if (s == NULL || e == NULL) + return -1; + + bprintk_fmt_s = s->value; + bprintk_fmt_e = e->value; + count = (bprintk_fmt_e - bprintk_fmt_s) / sizeof(long); + + if (count == 0) + goto do_mods; + + address = malloc(count * sizeof(long)); + if (address == NULL) + return -1; + + if (!readmem(bprintk_fmt_s, KVADDR, address, count * sizeof(long), + "get printk address", RETURN_ON_ERROR)) { + free(address); + return -1; + } + + for (i = 0; i < count; i++) { + if (add_print_address(address[i]) < 0) { + free(address); + return -1; + } + } + + free(address); + + do_mods: + + /* Add modules */ + b = symbol_search("trace_bprintk_fmt_list"); + if (!b) + goto out; + + switch (MEMBER_TYPE("trace_bprintk_fmt", "fmt")) { + case TYPE_CODE_ARRAY: + addr_is_array = 1; + break; + case TYPE_CODE_PTR: + default: + /* default not array */ + break; + } + + mod_fmt = (struct kernel_list_head *)GETBUF(SIZE(list_head)); + if (!readmem(b->value, KVADDR, mod_fmt, + SIZE(list_head), "trace_bprintk_fmt_list contents", + RETURN_ON_ERROR)) + goto out_free; + + while ((unsigned long)mod_fmt->next != b->value) { + unsigned long addr; + + addr = (unsigned long)mod_fmt->next + SIZE(list_head); + if (!addr_is_array) { + if (!readmem(addr, KVADDR, &addr, sizeof(addr), + "trace_bprintk_fmt_list fmt field", + RETURN_ON_ERROR)) + goto out_free; + } + + if (!readmem((unsigned long)mod_fmt->next, KVADDR, mod_fmt, + SIZE(list_head), "trace_bprintk_fmt_list contents", + RETURN_ON_ERROR)) + goto out_free; + + if (add_print_address(addr) < 0) + goto out_free; + count++; + } + + out_free: + FREEBUF(mod_fmt); + out: + if (count == 0) { + unsigned int size = 0; + return write_and_check(fd, &size, 4); + } + if (tmp_file_record_size4(fd)) + return -1; + return tmp_file_flush(fd); +} + +static int save_ftrace_cmdlines(int fd) +{ + int i; + struct task_context *tc = FIRST_CONTEXT(); + + for (i = 0; i < RUNNING_TASKS(); i++) + tmp_fprintf("%d %s\n", (int)tc[i].pid, tc[i].comm); + + if (tmp_file_record_size8(fd)) + return -1; + return tmp_file_flush(fd); +} + +static int save_res_data(int fd, int nr_cpu_buffers) +{ + unsigned short option = 0; + + if (write_and_check(fd, &nr_cpu_buffers, 4)) + return -1; + + if (write_and_check(fd, "options ", 10)) + return -1; + + if (write_and_check(fd, &option, 2)) + return -1; + + if (write_and_check(fd, "flyrecord", 10)) + return -1; + + return 0; +} + +static int save_record_data(int fd, int nr_cpu_buffers) +{ + int i, j; + unsigned long long offset, buffer_offset; + void *page_tmp; + + offset = lseek(fd, 0, SEEK_CUR); + offset += nr_cpu_buffers * 16; + offset = (offset + (PAGESIZE() - 1)) & ~(PAGESIZE() - 1); + buffer_offset = offset; + + for (i = 0; i < nr_cpu_ids; i++) { + struct ring_buffer_per_cpu *cpu_buffer = &global_buffers[i]; + unsigned long long buffer_size; + + if (!cpu_buffer->kaddr) + continue; + + buffer_size = PAGESIZE() * cpu_buffer->nr_linear_pages; + if (write_and_check(fd, &buffer_offset, 8)) + return -1; + if (write_and_check(fd, &buffer_size, 8)) + return -1; + buffer_offset += buffer_size; + } + + page_tmp = malloc(PAGESIZE()); + if (page_tmp == NULL) + return -1; + + lseek(fd, offset, SEEK_SET); + for (i = 0; i < nr_cpu_ids; i++) { + struct ring_buffer_per_cpu *cpu_buffer = &global_buffers[i]; + + if (!cpu_buffer->kaddr) + continue; + + for (j = 0; j < cpu_buffer->nr_linear_pages; j++) { + if (ftrace_dump_page(fd, cpu_buffer->linear_pages[j], + page_tmp) < 0) { + free(page_tmp); + return -1; + } + } + } + + free(page_tmp); + + return 0; +} + +static int __trace_cmd_data_output(int fd) +{ + int i; + int nr_cpu_buffers = 0; + + for (i = 0; i < nr_cpu_ids; i++) { + struct ring_buffer_per_cpu *cpu_buffer = &global_buffers[i]; + + if (!cpu_buffer->kaddr) + continue; + + nr_cpu_buffers++; + } + + if (save_initial_data(fd)) + return -1; + if (save_header_files(fd)) + return -1; + if (save_events_files(fd)) /* ftrace events and other systems events */ + return -1; + if (save_proc_kallsyms(fd)) + return -1; + if (save_ftrace_printk(fd)) + return -1; + if (save_ftrace_cmdlines(fd)) + return -1; + if (save_res_data(fd, nr_cpu_buffers)) + return -1; + if (save_record_data(fd, nr_cpu_buffers)) + return -1; + + return 0; +} + +static int trace_cmd_data_output(int fd) +{ + int ret; + + if (init_tmp_file()) + return -1; + + ret = __trace_cmd_data_output(fd); + destory_tmp_file(); + + return ret; +} diff --git a/filesys.c b/filesys.c new file mode 100644 index 00000000..5eec0fe1 --- /dev/null +++ b/filesys.c @@ -0,0 +1,4082 @@ +/* filesys.c - core analysis suite + * + * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2013 David Anderson + * Copyright (C) 2002-2013 Red Hat, Inc. 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. + */ + +#include "defs.h" +#include +#include +#include + +static void show_mounts(ulong, int, struct task_context *); +static int find_booted_kernel(void); +static int find_booted_system_map(void); +static int verify_utsname(char *); +static char **build_searchdirs(int, int *); +static int redhat_kernel_directory_v1(char *); +static int redhat_kernel_directory_v2(char *); +static int redhat_debug_directory(char *); +static ulong *create_dentry_array(ulong, int *); +static ulong *create_dentry_array_percpu(ulong, int *); +static void show_fuser(char *, char *); +static int mount_point(char *); +static int open_file_reference(struct reference *); +static void memory_source_init(void); +static int get_pathname_component(ulong, ulong, int, char *, char *); +static ulong *get_mount_list(int *, struct task_context *); +char *inode_type(char *, char *); +static void match_proc_version(void); +static void get_live_memory_source(void); +static int memory_driver_module_loaded(int *); +static int insmod_memory_driver_module(void); +static int get_memory_driver_dev(dev_t *); +static int memory_driver_init(void); +static int create_memory_device(dev_t); +static void *radix_tree_lookup(ulong, ulong, int); +static int match_file_string(char *, char *, char *); +static ulong get_root_vfsmount(char *); + + +#define DENTRY_CACHE (20) +#define INODE_CACHE (20) +#define FILE_CACHE (20) + +static struct filesys_table { + char *dentry_cache; + ulong cached_dentry[DENTRY_CACHE]; + ulong cached_dentry_hits[DENTRY_CACHE]; + int dentry_cache_index; + ulong dentry_cache_fills; + + char *inode_cache; + ulong cached_inode[INODE_CACHE]; + ulong cached_inode_hits[INODE_CACHE]; + int inode_cache_index; + ulong inode_cache_fills; + + char *file_cache; + ulong cached_file[FILE_CACHE]; + ulong cached_file_hits[FILE_CACHE]; + int file_cache_index; + ulong file_cache_fills; + +} filesys_table = { 0 }; + + +static struct filesys_table *ft = &filesys_table; + +/* + * Open the namelist, dumpfile and output devices. + */ +void +fd_init(void) +{ + pc->nfd = pc->kfd = pc->mfd = pc->dfd = -1; + + if ((pc->nullfp = fopen("/dev/null", "w+")) == NULL) + error(INFO, "cannot open /dev/null (for extraneous output)"); + + if (REMOTE()) + remote_fd_init(); + else { + if (pc->namelist && pc->namelist_debug && pc->system_map) { + error(INFO, + "too many namelist options:\n %s\n %s\n %s\n", + pc->namelist, pc->namelist_debug, + pc->system_map); + program_usage(SHORT_FORM); + } + + if (pc->namelist) { + if (XEN_HYPER_MODE() && !pc->dumpfile) + error(FATAL, + "Xen hypervisor mode requires a dumpfile\n"); + + if (!pc->dumpfile && !get_proc_version()) + error(INFO, "/proc/version: %s\n", + strerror(errno)); + } else { + if (pc->dumpfile) { + error(INFO, "namelist argument required\n"); + program_usage(SHORT_FORM); + } + if (!find_booted_kernel()) + program_usage(SHORT_FORM); + } + + if (!pc->dumpfile) { + pc->flags |= LIVE_SYSTEM; + get_live_memory_source(); + } + + if ((pc->nfd = open(pc->namelist, O_RDONLY)) < 0) + error(FATAL, "%s: %s\n", pc->namelist, strerror(errno)); + else { + close(pc->nfd); + pc->nfd = -1; + } + + if (ACTIVE() && !(pc->namelist_debug || pc->system_map)) { + memory_source_init(); + match_proc_version(); + } + + } + + memory_source_init(); + + if (CRASHDEBUG(1)) { + fprintf(fp, "readmem: %s() ", readmem_function_name()); + if (ACTIVE()) { + fprintf(fp, "-> %s ", pc->live_memsrc); + if (pc->flags & MEMMOD) + fprintf(fp, "(module)"); + else if (pc->flags & CRASHBUILTIN) + fprintf(fp, "(built-in)"); + } + fprintf(fp, "\n"); + } +} + +/* + * Do whatever's necessary to handle the memory source. + */ +static void +memory_source_init(void) +{ + if (REMOTE() && !(pc->flags & MEMSRC_LOCAL)) + return; + + if (pc->flags & KERNEL_DEBUG_QUERY) + return; + + if (ACTIVE()) { + if (pc->mfd != -1) /* already been here */ + return; + + if (!STREQ(pc->live_memsrc, "/dev/mem") && + STREQ(pc->live_memsrc, pc->memory_device)) { + if (memory_driver_init()) + return; + + error(INFO, "cannot initialize crash memory driver\n"); + error(INFO, "using /dev/mem\n\n"); + pc->flags &= ~MEMMOD; + pc->flags |= DEVMEM; + pc->readmem = read_dev_mem; + pc->writemem = write_dev_mem; + pc->live_memsrc = "/dev/mem"; + } + + if (STREQ(pc->live_memsrc, "/dev/mem")) { + if ((pc->mfd = open("/dev/mem", O_RDWR)) < 0) { + if ((pc->mfd = open("/dev/mem", O_RDONLY)) < 0) + error(FATAL, "/dev/mem: %s\n", + strerror(errno)); + } else + pc->flags |= MFD_RDWR; + } else if (STREQ(pc->live_memsrc, "/proc/kcore")) { + if ((pc->mfd = open("/proc/kcore", O_RDONLY)) < 0) + error(FATAL, "/proc/kcore: %s\n", + strerror(errno)); + if (!proc_kcore_init(fp)) + error(FATAL, + "/proc/kcore: initialization failed\n"); + } else + error(FATAL, "unknown memory device: %s\n", + pc->live_memsrc); + + return; + } + + if (pc->dumpfile) { + if (!file_exists(pc->dumpfile, NULL)) + error(FATAL, "%s: %s\n", pc->dumpfile, + strerror(ENOENT)); + + if (!(pc->flags & DUMPFILE_TYPES)) + error(FATAL, "%s: dump format not supported!\n", + pc->dumpfile); + + if (pc->flags & NETDUMP) { + if (!netdump_init(pc->dumpfile, fp)) + error(FATAL, "%s: initialization failed\n", + pc->dumpfile); + } else if (pc->flags & KDUMP) { + if (!kdump_init(pc->dumpfile, fp)) + error(FATAL, "%s: initialization failed\n", + pc->dumpfile); + } else if (pc->flags & XENDUMP) { + if (!xendump_init(pc->dumpfile, fp)) + error(FATAL, "%s: initialization failed\n", + pc->dumpfile); + } else if (pc->flags & KVMDUMP) { + if (!kvmdump_init(pc->dumpfile, fp)) + error(FATAL, "%s: initialization failed\n", + pc->dumpfile); + } else if (pc->flags & DISKDUMP) { + if (!diskdump_init(pc->dumpfile, fp)) + error(FATAL, "%s: initialization failed\n", + pc->dumpfile); + } else if (pc->flags & LKCD) { + if ((pc->dfd = open(pc->dumpfile, O_RDONLY)) < 0) + error(FATAL, "%s: %s\n", pc->dumpfile, + strerror(errno)); + if (!lkcd_dump_init(fp, pc->dfd, pc->dumpfile)) + error(FATAL, "%s: initialization failed\n", + pc->dumpfile); + } else if (pc->flags & S390D) { + if (!s390_dump_init(pc->dumpfile)) + error(FATAL, "%s: initialization failed\n", + pc->dumpfile); + } + } +} + +/* + * If only a namelist argument is entered for a live system, and the + * version string doesn't match /proc/version, try to avert a failure + * by assigning it to a matching System.map. + */ +static void +match_proc_version(void) +{ + char buffer[BUFSIZE], *p1, *p2; + + if (pc->flags & KERNEL_DEBUG_QUERY) + return; + + if (!strlen(kt->proc_version)) + return; + + if (match_file_string(pc->namelist, kt->proc_version, buffer)) { + if (CRASHDEBUG(1)) { + fprintf(fp, "/proc/version:\n%s\n", kt->proc_version); + fprintf(fp, "%s:\n%s", pc->namelist, buffer); + } + return; + } + + error(WARNING, "%s%sand /proc/version do not match!\n\n", + pc->namelist, + strlen(pc->namelist) > 39 ? "\n " : " "); + + /* + * find_booted_system_map() requires VTOP(), which used to be a + * hardwired masking of the kernel address. But some architectures + * may not know what their physical base address is at this point, + * and others may have different machdep->kvbase values, so for all + * but the 0-based kernel virtual address architectures, bail out + * here with a relevant error message. + */ + if (!machine_type("S390") && !machine_type("S390X")) { + p1 = &kt->proc_version[strlen("Linux version ")]; + p2 = strstr(p1, " "); + *p2 = NULLCHAR; + error(WARNING, "/proc/version indicates kernel version: %s\n", p1); + error(FATAL, "please use the vmlinux file for that kernel version, or try using\n" + " the System.map for that kernel version as an additional argument.\n", p1); + clean_exit(1); + } + + if (find_booted_system_map()) + pc->flags |= SYSMAP; +} + + +#define CREATE 1 +#define DESTROY 0 +#define DEFAULT_SEARCHDIRS 5 + +static char ** +build_searchdirs(int create, int *preferred) +{ + int i; + int cnt, start; + DIR *dirp; + struct dirent *dp; + char dirbuf[BUFSIZE]; + static char **searchdirs = { 0 }; + static char *default_searchdirs[DEFAULT_SEARCHDIRS+1] = { + "/usr/src/linux/", + "/boot/", + "/boot/efi/redhat", + "/boot/efi/EFI/redhat", + "/", + NULL + }; + + if (!create) { + if (searchdirs) { + for (i = DEFAULT_SEARCHDIRS; searchdirs[i]; i++) + free(searchdirs[i]); + free(searchdirs); + } + return NULL; + } + + if (preferred) + *preferred = 0; + + /* + * Allow, at a minimum, the defaults plus an extra three directories + * for the two possible /usr/src/redhat/BUILD/kernel-xxx locations + * plus the Red Hat debug directory. + */ + cnt = DEFAULT_SEARCHDIRS + 3; + + if ((dirp = opendir("/usr/src"))) { + for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) + cnt++; + + if ((searchdirs = calloc(cnt, sizeof(char *))) == NULL) { + error(INFO, "/usr/src/ directory list malloc: %s\n", + strerror(errno)); + closedir(dirp); + return default_searchdirs; + } + + for (i = 0; i < DEFAULT_SEARCHDIRS; i++) + searchdirs[i] = default_searchdirs[i]; + cnt = DEFAULT_SEARCHDIRS; + + rewinddir(dirp); + + for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { + if (STREQ(dp->d_name, "linux") || + STREQ(dp->d_name, "redhat") || + STREQ(dp->d_name, ".") || + STREQ(dp->d_name, "..")) + continue; + + sprintf(dirbuf, "/usr/src/%s", dp->d_name); + if (mount_point(dirbuf)) + continue; + if (!is_directory(dirbuf)) + continue; + + if ((searchdirs[cnt] = (char *) + malloc(strlen(dirbuf)+2)) == NULL) { + error(INFO, + "/usr/src/ directory entry malloc: %s\n", + strerror(errno)); + break; + } + sprintf(searchdirs[cnt], "%s/", dirbuf); + cnt++; + } + + closedir(dirp); + + searchdirs[cnt] = NULL; + } else { + if ((searchdirs = calloc(cnt, sizeof(char *))) == NULL) { + error(INFO, "search directory list malloc: %s\n", + strerror(errno)); + closedir(dirp); + return default_searchdirs; + } + for (i = 0; i < DEFAULT_SEARCHDIRS; i++) + searchdirs[i] = default_searchdirs[i]; + cnt = DEFAULT_SEARCHDIRS; + } + + if (redhat_kernel_directory_v1(dirbuf)) { + if ((searchdirs[cnt] = (char *) + malloc(strlen(dirbuf)+2)) == NULL) { + error(INFO, + "/usr/src/redhat directory entry malloc: %s\n", + strerror(errno)); + } else { + sprintf(searchdirs[cnt], "%s/", dirbuf); + cnt++; + } + } + + if (redhat_kernel_directory_v2(dirbuf)) { + if ((searchdirs[cnt] = (char *) + malloc(strlen(dirbuf)+2)) == NULL) { + error(INFO, + "/usr/src/redhat directory entry malloc: %s\n", + strerror(errno)); + } else { + sprintf(searchdirs[cnt], "%s/", dirbuf); + cnt++; + } + } + + if (redhat_debug_directory(dirbuf)) { + if ((searchdirs[cnt] = (char *) + malloc(strlen(dirbuf)+2)) == NULL) { + error(INFO, "%s directory entry malloc: %s\n", + dirbuf, strerror(errno)); + } else { + sprintf(searchdirs[cnt], "%s/", dirbuf); + if (preferred) + *preferred = cnt; + cnt++; + } + } + + searchdirs[cnt] = NULL; + + if (CRASHDEBUG(1)) { + i = start = preferred ? *preferred : 0; + do { + fprintf(fp, "searchdirs[%d]: %s\n", + i, searchdirs[i]); + if (++i == cnt) { + if (start != 0) + i = 0; + else + break; + } + } while (i != start); + } + + return searchdirs; +} + +static int +redhat_kernel_directory_v1(char *buf) +{ + char *p1, *p2; + + if (!strstr(kt->proc_version, "Linux version ")) + return FALSE; + + BZERO(buf, BUFSIZE); + sprintf(buf, "/usr/src/redhat/BUILD/kernel-"); + + p1 = &kt->proc_version[strlen("Linux version ")]; + p2 = &buf[strlen(buf)]; + + while (((*p1 >= '0') && (*p1 <= '9')) || (*p1 == '.')) + *p2++ = *p1++; + + strcat(buf, "/linux"); + return TRUE; +} + +static int +redhat_kernel_directory_v2(char *buf) +{ + char *p1, *p2; + + if (!strstr(kt->proc_version, "Linux version ")) + return FALSE; + + BZERO(buf, BUFSIZE); + sprintf(buf, "/usr/src/redhat/BUILD/kernel-"); + + p1 = &kt->proc_version[strlen("Linux version ")]; + p2 = &buf[strlen(buf)]; + + while (((*p1 >= '0') && (*p1 <= '9')) || (*p1 == '.')) + *p2++ = *p1++; + + strcat(buf, "/linux-"); + + p1 = &kt->proc_version[strlen("Linux version ")]; + p2 = &buf[strlen(buf)]; + + while (((*p1 >= '0') && (*p1 <= '9')) || (*p1 == '.')) + *p2++ = *p1++; + + return TRUE; +} + + +static int +redhat_debug_directory(char *buf) +{ + char *p1, *p2; + + if (!strstr(kt->proc_version, "Linux version ")) + return FALSE; + + BZERO(buf, BUFSIZE); + sprintf(buf, "%s/", pc->redhat_debug_loc); + + p1 = &kt->proc_version[strlen("Linux version ")]; + p2 = &buf[strlen(buf)]; + + while (*p1 != ' ') + *p2++ = *p1++; + + return TRUE; +} + +/* + * If a namelist was not entered, presume we're using the currently-running + * kernel. Read its version string from /proc/version, and then look in + * the search directories for a kernel with the same version string embedded + * in it. + */ +static int +find_booted_kernel(void) +{ + char kernel[BUFSIZE]; + char buffer[BUFSIZE]; + char **searchdirs; + int i, preferred, wrapped; + DIR *dirp; + struct dirent *dp; + int found; + + pc->flags |= FINDKERNEL; + + fflush(fp); + + if (!file_exists("/proc/version", NULL)) { + error(INFO, + "/proc/version: %s: cannot determine booted kernel\n", + strerror(ENOENT)); + return FALSE; + } + + if (!get_proc_version()) { + error(INFO, "/proc/version: %s\n", strerror(errno)); + return FALSE; + } + + if (CRASHDEBUG(1)) + fprintf(fp, "\nfind_booted_kernel: search for [%s]\n", + kt->proc_version); + + searchdirs = build_searchdirs(CREATE, &preferred); + + for (i = preferred, wrapped = found = FALSE; !found; i++) { + if (!searchdirs[i]) { + if (preferred && !wrapped) { + wrapped = TRUE; + i = 0; + } else + break; + } else if (wrapped && (preferred == i)) + break; + + dirp = opendir(searchdirs[i]); + if (!dirp) + continue; + for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { + if (dp->d_name[0] == '.') + continue; + + sprintf(kernel, "%s%s", searchdirs[i], dp->d_name); + + if (mount_point(kernel) || + !file_readable(kernel) || + !is_elf_file(kernel)) + continue; + + if (CRASHDEBUG(1)) + fprintf(fp, "find_booted_kernel: check: %s\n", + kernel); + + found = match_file_string(kernel, kt->proc_version, buffer); + + if (found) + break; + } + closedir(dirp); + } + + mount_point(DESTROY); + build_searchdirs(DESTROY, NULL); + + if (found) { + if ((pc->namelist = (char *)malloc + (strlen(kernel)+1)) == NULL) + error(FATAL, "booted kernel name malloc: %s\n", + strerror(errno)); + else { + strcpy(pc->namelist, kernel); + if (CRASHDEBUG(1)) + fprintf(fp, "find_booted_kernel: found: %s\n", + pc->namelist); + return TRUE; + } + } + + error(INFO, + "cannot find booted kernel -- please enter namelist argument\n\n"); + return FALSE; +} + +/* + * Determine whether a file is a mount point, without the benefit of stat(). + * This horrendous kludge is necessary to avoid uninterruptible stat() or + * fstat() calls on nfs mount-points where the remote directory is no longer + * available. + */ +static int +mount_point(char *name) +{ + int i; + static int mount_points_gathered = -1; + static char **mount_points; + char *arglist[MAXARGS]; + char buf[BUFSIZE]; + char mntfile[BUFSIZE]; + int argc, found; + FILE *mp; + + /* + * The first time through, stash a list of mount points. + */ + + if (mount_points_gathered < 0) { + found = mount_points_gathered = 0; + + if (file_exists("/proc/mounts", NULL)) + sprintf(mntfile, "/proc/mounts"); + else if (file_exists("/etc/mtab", NULL)) + sprintf(mntfile, "/etc/mtab"); + else + return FALSE; + + if ((mp = fopen(mntfile, "r")) == NULL) + return FALSE; + + while (fgets(buf, BUFSIZE, mp)) { + argc = parse_line(buf, arglist); + if (argc < 2) + continue; + found++; + } + pclose(mp); + + if (!(mount_points = (char **)malloc(sizeof(char *) * found))) + return FALSE; + + if ((mp = fopen(mntfile, "r")) == NULL) + return FALSE; + + i = 0; + while (fgets(buf, BUFSIZE, mp) && + (mount_points_gathered < found)) { + argc = parse_line(buf, arglist); + if (argc < 2) + continue; + if ((mount_points[i] = (char *) + malloc(strlen(arglist[1])*2))) { + strcpy(mount_points[i], arglist[1]); + mount_points_gathered++, i++; + } + } + pclose(mp); + + if (CRASHDEBUG(2)) + for (i = 0; i < mount_points_gathered; i++) + fprintf(fp, "mount_points[%d]: %s (%lx)\n", + i, mount_points[i], + (ulong)mount_points[i]); + + } + + /* + * A null name string means we're done with this routine forever, + * so the malloc'd memory can be freed. + */ + if (!name) { + for (i = 0; i < mount_points_gathered; i++) + free(mount_points[i]); + free(mount_points); + return FALSE; + } + + + for (i = 0; i < mount_points_gathered; i++) { + if (STREQ(name, mount_points[i])) + return TRUE; + } + + + return FALSE; +} + + +/* + * If /proc/version exists, get it for verification purposes later. + */ +int +get_proc_version(void) +{ + FILE *version; + + if (strlen(kt->proc_version)) /* been here, done that... */ + return TRUE; + + if (!file_exists("/proc/version", NULL)) + return FALSE; + + if ((version = fopen("/proc/version", "r")) == NULL) + return FALSE; + + if (fread(&kt->proc_version, sizeof(char), + BUFSIZE-1, version) <= 0) { + fclose(version); + return FALSE; + } + + fclose(version); + + strip_linefeeds(kt->proc_version); + + return TRUE; +} + + +/* + * Given a non-matching kernel namelist, try to find a System.map file + * that has a system_utsname whose contents match /proc/version. + */ +static int +find_booted_system_map(void) +{ + char system_map[BUFSIZE]; + char **searchdirs; + int i; + DIR *dirp; + struct dirent *dp; + int found; + + fflush(fp); + + if (!file_exists("/proc/version", NULL)) { + error(INFO, + "/proc/version: %s: cannot determine booted System.map\n", + strerror(ENOENT)); + return FALSE; + } + + if (!get_proc_version()) { + error(INFO, "/proc/version: %s\n", strerror(errno)); + return FALSE; + } + + found = FALSE; + + /* + * To avoid a search, try the obvious first. + */ + sprintf(system_map, "/boot/System.map"); + if (file_readable(system_map) && verify_utsname(system_map)) { + found = TRUE; + } else { + searchdirs = build_searchdirs(CREATE, NULL); + + for (i = 0; !found && searchdirs[i]; i++) { + dirp = opendir(searchdirs[i]); + if (!dirp) + continue; + for (dp = readdir(dirp); dp != NULL; + dp = readdir(dirp)) { + if (!strstr(dp->d_name, "System.map")) + continue; + + sprintf(system_map, "%s%s", searchdirs[i], + dp->d_name); + + if (mount_point(system_map) || + !file_readable(system_map) || + !is_system_map(system_map)) + continue; + + if (verify_utsname(system_map)) { + found = TRUE; + break; + } + } + closedir(dirp); + } + + mount_point(DESTROY); + build_searchdirs(DESTROY, NULL); + } + + if (found) { + if ((pc->system_map = (char *)malloc + (strlen(system_map)+1)) == NULL) + error(FATAL, "booted system map name malloc: %s\n", + strerror(errno)); + strcpy(pc->system_map, system_map); + if (CRASHDEBUG(1)) + fprintf(fp, "find_booted_system_map: found: %s\n", + pc->system_map); + return TRUE; + } + + error(INFO, + "cannot find booted system map -- please enter namelist or system map\n\n"); + return FALSE; +} + +/* + * Read the system_utsname from /dev/mem, based upon the address found + * in the passed-in System.map file, and compare it to /proc/version. + */ +static int +verify_utsname(char *system_map) +{ + char buffer[BUFSIZE]; + ulong value; + struct new_utsname new_utsname; + + if (CRASHDEBUG(1)) + fprintf(fp, "verify_utsname: check: %s\n", system_map); + + if (!match_file_string(system_map, "D system_utsname", buffer)) + return FALSE; + + if (extract_hex(buffer, &value, NULLCHAR, TRUE) && + (READMEM(pc->mfd, &new_utsname, + sizeof(struct new_utsname), value, + VTOP(value)) > 0) && + ascii_string(new_utsname.release) && + ascii_string(new_utsname.version) && + STRNEQ(new_utsname.release, "2.") && + (strlen(new_utsname.release) > 4) && + (strlen(new_utsname.version) > 27)) { + if (CRASHDEBUG(1)) { + fprintf(fp, "release: [%s]\n", new_utsname.release); + fprintf(fp, "version: [%s]\n", new_utsname.version); + } + if (strstr(kt->proc_version, new_utsname.release) && + strstr(kt->proc_version, new_utsname.version)) { + return TRUE; + } + } + + return FALSE; +} + +/* + * Determine whether a file exists, using the caller's stat structure if + * one was passed in. + */ +int +file_exists(char *file, struct stat *sp) +{ + struct stat sbuf; + + if (stat(file, sp ? sp : &sbuf) == 0) + return TRUE; + + return FALSE; +} + +/* + * Determine whether a file exists, and if so, if it's readable. + */ +int +file_readable(char *file) +{ + char tmp; + int fd; + + if (!file_exists(file, NULL)) + return FALSE; + + if ((fd = open(file, O_RDONLY)) < 0) + return FALSE; + + if (read(fd, &tmp, sizeof(tmp)) != sizeof(tmp)) { + close(fd); + return FALSE; + } + close(fd); + + return TRUE; +} + +/* + * Quick file checksummer. + */ +int +file_checksum(char *file, long *retsum) +{ + int i; + int fd; + ssize_t cnt; + char buf[MIN_PAGE_SIZE]; + long csum; + + + if ((fd = open(file, O_RDONLY)) < 0) + return FALSE; + + csum = 0; + BZERO(buf, MIN_PAGE_SIZE); + while ((cnt = read(fd, buf, MIN_PAGE_SIZE)) > 0) { + for (i = 0; i < cnt; i++) + csum += buf[i]; + BZERO(buf, MIN_PAGE_SIZE); + } + close(fd); + + *retsum = csum; + + return TRUE; +} + +int +is_directory(char *file) +{ + struct stat sbuf; + + if (!file || !strlen(file)) + return(FALSE); + + if (stat(file, &sbuf) == -1) + return(FALSE); /* This file doesn't exist. */ + + return((sbuf.st_mode & S_IFMT) == S_IFDIR ? TRUE : FALSE); +} + + +/* + * Search a directory tree for filename, and if found, return a temporarily + * allocated buffer containing the full pathname. The "done" business is + * protection against fgets() prematurely returning NULL before the find + * command completes. (I thought this was impossible until I saw it happen...) + * When time permits, rewrite this doing the search by hand. + */ +char * +search_directory_tree(char *directory, char *file, int follow_links) +{ + char command[BUFSIZE]; + char buf[BUFSIZE]; + char *retbuf, *start, *end, *module; + FILE *pipe; + regex_t regex; + int regex_used, done; + + if (!file_exists("/usr/bin/find", NULL) || + !file_exists("/bin/echo", NULL) || + !is_directory(directory) || + (*file == '(')) + return NULL; + + sprintf(command, + "/usr/bin/find %s %s -name %s -print; /bin/echo search done", + follow_links ? "-L" : "", directory, file); + + if ((pipe = popen(command, "r")) == NULL) { + error(INFO, "%s: %s\n", command, strerror(errno)); + return NULL; + } + + done = FALSE; + retbuf = NULL; + regex_used = ((start = strstr(file, "[")) && + (end = strstr(file, "]")) && (start < end) && + (regcomp(®ex, file, 0) == 0)); + + while (fgets(buf, BUFSIZE-1, pipe) || !done) { + if (STREQ(buf, "search done\n")) { + done = TRUE; + break; + } + if (!retbuf && !regex_used && + STREQ((char *)basename(strip_linefeeds(buf)), file)) { + retbuf = GETBUF(strlen(buf)+1); + strcpy(retbuf, buf); + } + if (!retbuf && regex_used) { + module = basename(strip_linefeeds(buf)); + if (regexec(®ex, module, 0, NULL, 0) == 0) { + retbuf = GETBUF(strlen(buf)+1); + strcpy(retbuf, buf); + } + } + } + + if (regex_used) + regfree(®ex); + + pclose(pipe); + + return retbuf; +} + +/* + * Determine whether a file exists, and if so, if it's a tty. + */ +int +is_a_tty(char *filename) +{ + int fd; + + if ((fd = open(filename, O_RDONLY)) < 0) + return FALSE; + + if (isatty(fd)) { + close(fd); + return TRUE; + } + + close(fd); + return FALSE; +} + +/* + * Open a tmpfile for command output. fp is stashed in pc->saved_fp, and + * temporarily set to the new FILE pointer. This allows a command to still + * print to the original output while the tmpfile is still open. + */ + +#define OPEN_ONLY_ONCE + +#ifdef OPEN_ONLY_ONCE +void +open_tmpfile(void) +{ + int ret ATTRIBUTE_UNUSED; + + if (pc->tmpfile) + error(FATAL, "recursive temporary file usage\n"); + + if (!pc->tmp_fp) { + if ((pc->tmp_fp = tmpfile()) == NULL) + error(FATAL, "cannot open temporary file\n"); + } + + fflush(pc->tmpfile); + ret = ftruncate(fileno(pc->tmp_fp), 0); + rewind(pc->tmp_fp); + + pc->tmpfile = pc->tmp_fp; + pc->saved_fp = fp; + fp = pc->tmpfile; +} +#else +void +open_tmpfile(void) +{ + if (pc->tmpfile) + error(FATAL, "recursive temporary file usage\n"); + + if ((pc->tmpfile = tmpfile()) == NULL) { + error(FATAL, "cannot open temporary file\n"); + } else { + pc->saved_fp = fp; + fp = pc->tmpfile; + } +} +#endif + +/* + * Destroy the reference to the tmpfile, and restore fp to the state + * it had when open_tmpfile() was called. + */ +#ifdef OPEN_ONLY_ONCE +void +close_tmpfile(void) +{ + int ret ATTRIBUTE_UNUSED; + + if (pc->tmpfile) { + fflush(pc->tmpfile); + ret = ftruncate(fileno(pc->tmpfile), 0); + rewind(pc->tmpfile); + pc->tmpfile = NULL; + fp = pc->saved_fp; + } else + error(FATAL, "trying to close an unopened temporary file\n"); +} +#else +void +close_tmpfile(void) +{ + if (pc->tmpfile) { + fp = pc->saved_fp; + fclose(pc->tmpfile); + pc->tmpfile = NULL; + } else + error(FATAL, "trying to close an unopened temporary file\n"); + +} +#endif + +/* + * open_tmpfile2(), set_tmpfile2() and close_tmpfile2() do not use a + * permanent tmpfile, and do NOT modify the global fp pointer or pc->saved_fp. + * That being the case, all wrapped functions must be aware of it, or the + * global fp pointer has to explicitly manipulated by the calling function. + * The secondary tmpfile should only be used by common functions that might + * be called by a higher-level function using the primary permanent tmpfile, + * or alternatively a caller may pass in a FILE pointer to set_tmpfile2(). + */ +void +open_tmpfile2(void) +{ + if (pc->tmpfile2) + error(FATAL, "recursive secondary temporary file usage\n"); + + if ((pc->tmpfile2 = tmpfile()) == NULL) + error(FATAL, "cannot open secondary temporary file\n"); + + rewind(pc->tmpfile2); +} + +void +close_tmpfile2(void) +{ + if (pc->tmpfile2) { + fflush(pc->tmpfile2); + fclose(pc->tmpfile2); + pc->tmpfile2 = NULL; + } +} + +void +set_tmpfile2(FILE *fptr) +{ + if (pc->tmpfile2) + error(FATAL, "secondary temporary file already in use\n"); + + pc->tmpfile2 = fptr; +} + + +#define MOUNT_PRINT_INODES 0x1 +#define MOUNT_PRINT_FILES 0x2 + +/* + * Display basic information about the currently mounted filesystems. + * The -f option lists the open files for the filesystem(s). + * The -i option dumps the dirty inodes of the filesystem(s). + * If an inode address, mount, vfsmount, superblock, device name or + * directory name is also entered, just show the data for the + * filesystem indicated by the argument. + */ + +static char mount_hdr[BUFSIZE] = { 0 }; + +void +cmd_mount(void) +{ + int i; + int c, found; + struct task_context *tc, *namespace_context; + ulong value1, value2; + char *spec_string; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char *arglist[MAXARGS*2]; + ulong vfsmount = 0; + int flags = 0; + int save_next; + ulong pid; + + /* find a context */ + pid = 1; + while ((namespace_context = pid_to_context(pid)) == NULL) + pid++; + + while ((c = getopt(argcnt, args, "ifn:")) != EOF) { + switch(c) + { + case 'i': + if (INVALID_MEMBER(super_block_s_dirty)) { + error(INFO, + "the super_block.s_dirty linked list does " + "not exist in this kernel\n"); + option_not_supported(c); + } + flags |= MOUNT_PRINT_INODES; + break; + + case 'f': + flags |= MOUNT_PRINT_FILES; + break; + + case 'n': + switch (str_to_context(optarg, &value1, &tc)) { + case STR_PID: + case STR_TASK: + namespace_context = tc; + break; + case STR_INVALID: + error(FATAL, "invalid task or pid value: %s\n", + optarg); + break; + } + break; + + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + if (args[optind] == 0) { + show_mounts(0, flags, namespace_context); + return; + } + + /* + * Dump everything into a tmpfile, and then walk + * through it for each search argument entered. + */ + open_tmpfile(); + show_mounts(0, MOUNT_PRINT_FILES | + (VALID_MEMBER(super_block_s_dirty) ? MOUNT_PRINT_INODES : 0), + namespace_context); + + do { + spec_string = args[optind]; + if (STRNEQ(spec_string, "0x") && + hexadecimal(spec_string, 0)) + shift_string_left(spec_string, 2); + + found = FALSE; + rewind(pc->tmpfile); + save_next = 0; + + while (fgets(buf1, BUFSIZE, pc->tmpfile)) { + if (STRNEQ(buf1, mount_hdr)) { + save_next = TRUE; + continue; + } + if (save_next) { + strcpy(buf2, buf1); + save_next = FALSE; + } + + if (!(c = parse_line(buf1, arglist))) + continue; + + for (i = 0; i < c; i++) { + if (PATHEQ(arglist[i], spec_string)) + found = TRUE; + /* + * Check for a vfsmount address + * embedded in a struct mount. + */ + if ((i == 0) && (c == 5) && + VALID_MEMBER(mount_mnt) && + hexadecimal(spec_string, 0) && + hexadecimal(arglist[i], 0)) { + value1 = htol(spec_string, + FAULT_ON_ERROR, NULL); + value2 = htol(arglist[i], + FAULT_ON_ERROR, NULL) + + OFFSET(mount_mnt); + if (value1 == value2) + found = TRUE; + } + } + if (found) { + fp = pc->saved_fp; + if (flags) { + sscanf(buf2,"%lx", &vfsmount); + show_mounts(vfsmount, flags, + namespace_context); + } else { + if (!(pc->curcmd_flags & HEADER_PRINTED)) { + fprintf(fp, "%s", mount_hdr); + pc->curcmd_flags |= HEADER_PRINTED; + } + fprintf(fp, "%s", buf2); + } + found = FALSE; + fp = pc->tmpfile; + } + } + } while (args[++optind]); + + close_tmpfile(); +} + +/* + * Do the work for cmd_mount(); + */ + +static void +show_mounts(ulong one_vfsmount, int flags, struct task_context *namespace_context) +{ + ulong one_vfsmount_list; + long sb_s_files; + long s_dirty; + ulong devp, dirp, sbp, dirty, type, name; + struct list_data list_data, *ld; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char buf3[BUFSIZE]; + char buf4[BUFSIZE]; + ulong *dentry_list, *dp, *mntlist; + ulong *vfsmnt; + char *vfsmount_buf, *super_block_buf, *mount_buf; + ulong dentry, inode, inode_sb, mnt_parent; + char *dentry_buf, *inode_buf; + int cnt, i, m, files_header_printed; + int mount_cnt; + int devlen; + char mount_files_header[BUFSIZE]; + long per_cpu_s_files; + + sprintf(mount_files_header, "%s%s%s%sTYPE%sPATH\n", + mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "DENTRY"), + space(MINSPACE), + mkstring(buf2, VADDR_PRLEN, CENTER|LJUST, "INODE"), + space(MINSPACE), + space(MINSPACE)); + + dirp = dentry = mnt_parent = sb_s_files = s_dirty = 0; + + if (VALID_MEMBER(super_block_s_dirty)) + s_dirty = OFFSET(super_block_s_dirty); + + per_cpu_s_files = MEMBER_EXISTS("file", "f_sb_list_cpu"); + + dentry_list = NULL; + mntlist = 0; + ld = &list_data; + + if (one_vfsmount) { + one_vfsmount_list = one_vfsmount; + mount_cnt = 1; + mntlist = &one_vfsmount_list; + } else + mntlist = get_mount_list(&mount_cnt, namespace_context); + + devlen = strlen("DEVNAME")+2; + + if (!strlen(mount_hdr)) { + snprintf(mount_hdr, sizeof(mount_hdr), "%s %s %s %s DIRNAME\n", + mkstring(buf1, VADDR_PRLEN, CENTER, + VALID_STRUCT(mount) ? "MOUNT" : "VFSMOUNT"), + mkstring(buf2, VADDR_PRLEN, CENTER, "SUPERBLK"), + mkstring(buf3, strlen("rootfs"), LJUST, "TYPE"), + mkstring(buf4, devlen, LJUST, "DEVNAME")); + } + + if (flags == 0) + fprintf(fp, "%s", mount_hdr); + + if ((flags & MOUNT_PRINT_FILES) && + (sb_s_files = OFFSET(super_block_s_files)) == INVALID_OFFSET) { + /* + * No open files list in super_block (2.2). + * Use inuse_filps list instead. + */ + dentry_list = create_dentry_array(symbol_value("inuse_filps"), + &cnt); + } + + if (VALID_STRUCT(mount)) { + mount_buf = GETBUF(SIZE(mount)); + vfsmount_buf = mount_buf + OFFSET(mount_mnt); + } else { + mount_buf = NULL; + vfsmount_buf = GETBUF(SIZE(vfsmount)); + } + super_block_buf = GETBUF(SIZE(super_block)); + + for (m = 0, vfsmnt = mntlist; m < mount_cnt; m++, vfsmnt++) { + if (VALID_STRUCT(mount)) { + readmem(*vfsmnt, KVADDR, mount_buf, SIZE(mount), + "mount buffer", FAULT_ON_ERROR); + devp = ULONG(mount_buf + OFFSET(mount_mnt_devname)); + } else { + readmem(*vfsmnt, KVADDR, vfsmount_buf, SIZE(vfsmount), + "vfsmount buffer", FAULT_ON_ERROR); + devp = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_devname)); + } + + if (VALID_MEMBER(vfsmount_mnt_dirname)) { + dirp = ULONG(vfsmount_buf + + OFFSET(vfsmount_mnt_dirname)); + } else { + if (VALID_STRUCT(mount)) { + mnt_parent = ULONG(mount_buf + + OFFSET(mount_mnt_parent)); + dentry = ULONG(mount_buf + + OFFSET(mount_mnt_mountpoint)); + } else { + mnt_parent = ULONG(vfsmount_buf + + OFFSET(vfsmount_mnt_parent)); + dentry = ULONG(vfsmount_buf + + OFFSET(vfsmount_mnt_mountpoint)); + } + } + + sbp = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_sb)); + + if (flags) + fprintf(fp, "%s", mount_hdr); + fprintf(fp, "%s %s ", + mkstring(buf1, VADDR_PRLEN, RJUST|LONG_HEX, + MKSTR(*vfsmnt)), + mkstring(buf2, VADDR_PRLEN, RJUST|LONG_HEX, + MKSTR(sbp))); + + readmem(sbp, KVADDR, super_block_buf, SIZE(super_block), + "super_block buffer", FAULT_ON_ERROR); + type = ULONG(super_block_buf + OFFSET(super_block_s_type)); + readmem(type + OFFSET(file_system_type_name), + KVADDR, &name, sizeof(void *), + "file_system_type name", FAULT_ON_ERROR); + + if (read_string(name, buf1, BUFSIZE-1)) + sprintf(buf3, "%-6s ", buf1); + else + sprintf(buf3, "unknown "); + + if (read_string(devp, buf1, BUFSIZE-1)) + sprintf(buf4, "%s ", + mkstring(buf2, devlen, LJUST, buf1)); + else + sprintf(buf4, "%s ", + mkstring(buf2, devlen, LJUST, "(unknown)")); + + sprintf(buf1, "%s%s", buf3, buf4); + while ((strlen(buf1) > 17) && (buf1[strlen(buf1)-2] == ' ')) + strip_ending_char(buf1, ' '); + fprintf(fp, "%s", buf1); + + if (VALID_MEMBER(vfsmount_mnt_dirname)) { + if (read_string(dirp, buf1, BUFSIZE-1)) + fprintf(fp, "%-10s\n", buf1); + else + fprintf(fp, "%-10s\n", "(unknown)"); + } else { + get_pathname(dentry, buf1, BUFSIZE, 1, VALID_STRUCT(mount) ? + mnt_parent + OFFSET(mount_mnt) : mnt_parent); + fprintf(fp, "%-10s\n", buf1); + } + + if (flags & MOUNT_PRINT_FILES) { + if (sb_s_files != INVALID_OFFSET) { + dentry_list = per_cpu_s_files ? + create_dentry_array_percpu(sbp+ + sb_s_files, &cnt) : + create_dentry_array(sbp+sb_s_files, + &cnt); + } + files_header_printed = 0; + for (i=0, dp = dentry_list; iflags = VERBOSE; + ld->start = dirty; + ld->end = (sbp+s_dirty); + ld->header = "DIRTY INODES\n"; + hq_open(); + do_list(ld); + hq_close(); + } else { + fprintf(fp, + "DIRTY INODES\nNo dirty inodes found\n"); + } + } + + if (flags && !one_vfsmount) + fprintf(fp, "\n"); + + } + + if (!one_vfsmount) + FREEBUF(mntlist); + if (VALID_STRUCT(mount)) + FREEBUF(mount_buf); + else + FREEBUF(vfsmount_buf); + FREEBUF(super_block_buf); +} + +/* + * Allocate and fill a list of the currently-mounted vfsmount pointers. + */ +static ulong * +get_mount_list(int *cntptr, struct task_context *namespace_context) +{ + struct list_data list_data, *ld; + ulong namespace, root, nsproxy, mnt_ns; + struct task_context *tc; + + ld = &list_data; + BZERO(ld, sizeof(struct list_data)); + ld->flags |= LIST_ALLOCATE; + + if (symbol_exists("vfsmntlist")) { + get_symbol_data("vfsmntlist", sizeof(void *), &ld->start); + ld->end = symbol_value("vfsmntlist"); + } else if (VALID_MEMBER(task_struct_nsproxy)) { + tc = namespace_context; + + readmem(tc->task + OFFSET(task_struct_nsproxy), KVADDR, + &nsproxy, sizeof(void *), "task nsproxy", + FAULT_ON_ERROR); + if (!readmem(nsproxy + OFFSET(nsproxy_mnt_ns), KVADDR, + &mnt_ns, sizeof(void *), "nsproxy mnt_ns", + RETURN_ON_ERROR|QUIET)) + error(FATAL, "cannot determine mount list location!\n"); + if (!readmem(mnt_ns + OFFSET(mnt_namespace_root), KVADDR, + &root, sizeof(void *), "mnt_namespace root", + RETURN_ON_ERROR|QUIET)) + error(FATAL, "cannot determine mount list location!\n"); + + ld->start = root + OFFSET_OPTION(vfsmount_mnt_list, mount_mnt_list); + ld->end = mnt_ns + OFFSET(mnt_namespace_list); + + } else if (VALID_MEMBER(namespace_root)) { + tc = namespace_context; + + readmem(tc->task + OFFSET(task_struct_namespace), KVADDR, + &namespace, sizeof(void *), "task namespace", + FAULT_ON_ERROR); + if (!readmem(namespace + OFFSET(namespace_root), KVADDR, + &root, sizeof(void *), "namespace root", + RETURN_ON_ERROR|QUIET)) + error(FATAL, "cannot determine mount list location!\n"); + + if (CRASHDEBUG(1)) + console("namespace: %lx => root: %lx\n", + namespace, root); + + ld->start = root + OFFSET_OPTION(vfsmount_mnt_list, mount_mnt_list); + ld->end = namespace + OFFSET(namespace_list); + } else + error(FATAL, "cannot determine mount list location!\n"); + + if (VALID_MEMBER(vfsmount_mnt_list)) + ld->list_head_offset = OFFSET(vfsmount_mnt_list); + else if (VALID_STRUCT(mount)) + ld->list_head_offset = OFFSET(mount_mnt_list); + else + ld->member_offset = OFFSET(vfsmount_mnt_next); + + *cntptr = do_list(ld); + return(ld->list_ptr); +} + + +/* + * Given a dentry, display its address, inode, super_block, pathname. + */ +static void +display_dentry_info(ulong dentry) +{ + int m, found; + char *dentry_buf, *inode_buf, *vfsmount_buf, *mount_buf; + ulong inode, superblock, sb, vfs; + ulong *mntlist, *vfsmnt; + char pathname[BUFSIZE]; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char buf3[BUFSIZE]; + int mount_cnt; + + fprintf(fp, "%s%s%s%s%s%sTYPE%sPATH\n", + mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "DENTRY"), + space(MINSPACE), + mkstring(buf2, VADDR_PRLEN, CENTER|LJUST, "INODE"), + space(MINSPACE), + mkstring(buf3, VADDR_PRLEN, CENTER|LJUST, "SUPERBLK"), + space(MINSPACE), + space(MINSPACE)); + + dentry_buf = fill_dentry_cache(dentry); + inode = ULONG(dentry_buf + OFFSET(dentry_d_inode)); + pathname[0] = NULLCHAR; + + if (inode) { + inode_buf = fill_inode_cache(inode); + superblock = ULONG(inode_buf + OFFSET(inode_i_sb)); + } else { + inode_buf = NULL; + superblock = 0; + } + + if (!inode || !superblock) + goto nopath; + + if (VALID_MEMBER(file_f_vfsmnt)) { + mntlist = get_mount_list(&mount_cnt, pid_to_context(1)); + if (VALID_STRUCT(mount)) { + mount_buf = GETBUF(SIZE(mount)); + vfsmount_buf = mount_buf + OFFSET(mount_mnt); + } else { + mount_buf = NULL; + vfsmount_buf = GETBUF(SIZE(vfsmount)); + } + + for (m = found = 0, vfsmnt = mntlist; + m < mount_cnt; m++, vfsmnt++) { + if (VALID_STRUCT(mount)) + readmem(*vfsmnt, KVADDR, mount_buf, SIZE(mount), + "mount buffer", FAULT_ON_ERROR); + else + readmem(*vfsmnt, KVADDR, vfsmount_buf, SIZE(vfsmount), + "vfsmount buffer", FAULT_ON_ERROR); + sb = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_sb)); + if (superblock && (sb == superblock)) { + get_pathname(dentry, pathname, BUFSIZE, 1, + VALID_STRUCT(mount) ? + *vfsmnt+OFFSET(mount_mnt) : *vfsmnt); + found = TRUE; + } + } + + if (!found && symbol_exists("pipe_mnt")) { + get_symbol_data("pipe_mnt", sizeof(long), &vfs); + if (VALID_STRUCT(mount)) + readmem(vfs - OFFSET(mount_mnt), KVADDR, mount_buf, SIZE(mount), + "mount buffer", FAULT_ON_ERROR); + else + readmem(vfs, KVADDR, vfsmount_buf, SIZE(vfsmount), + "vfsmount buffer", FAULT_ON_ERROR); + sb = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_sb)); + if (superblock && (sb == superblock)) { + get_pathname(dentry, pathname, BUFSIZE, 1, vfs); + found = TRUE; + } + } + if (!found && symbol_exists("sock_mnt")) { + get_symbol_data("sock_mnt", sizeof(long), &vfs); + if (VALID_STRUCT(mount)) + readmem(vfs - OFFSET(mount_mnt), KVADDR, mount_buf, SIZE(mount), + "mount buffer", FAULT_ON_ERROR); + else + readmem(vfs, KVADDR, vfsmount_buf, SIZE(vfsmount), + "vfsmount buffer", FAULT_ON_ERROR); + sb = ULONG(vfsmount_buf + OFFSET(vfsmount_mnt_sb)); + if (superblock && (sb == superblock)) { + get_pathname(dentry, pathname, BUFSIZE, 1, vfs); + found = TRUE; + } + } + } else { + mntlist = 0; + get_pathname(dentry, pathname, BUFSIZE, 1, 0); + } + + if (mntlist) { + FREEBUF(mntlist); + if (VALID_STRUCT(mount)) + FREEBUF(mount_buf); + else + FREEBUF(vfsmount_buf); + } + +nopath: + fprintf(fp, "%s%s%s%s%s%s%s%s%s\n", + mkstring(buf1, VADDR_PRLEN, RJUST|LONG_HEX, MKSTR(dentry)), + space(MINSPACE), + mkstring(buf2, VADDR_PRLEN, RJUST|LONG_HEX, MKSTR(inode)), + space(MINSPACE), + mkstring(buf3, VADDR_PRLEN, CENTER|LONG_HEX, MKSTR(superblock)), + space(MINSPACE), + inode ? inode_type(inode_buf, pathname) : "N/A", + space(MINSPACE), pathname); +} + +/* + * Return a 4-character type string of an inode, modifying a previously + * gathered pathname if necessary. + */ +char * +inode_type(char *inode_buf, char *pathname) +{ + char *type; + uint32_t umode32; + uint16_t umode16; + uint mode; + ulong inode_i_op; + ulong inode_i_fop; + long i_fop_off; + + mode = umode16 = umode32 = 0; + + switch (SIZE(umode_t)) + { + case SIZEOF_32BIT: + umode32 = UINT(inode_buf + OFFSET(inode_i_mode)); + mode = umode32; + break; + + case SIZEOF_16BIT: + umode16 = USHORT(inode_buf + OFFSET(inode_i_mode)); + mode = (uint)umode16; + break; + } + + type = "UNKN"; + if (S_ISREG(mode)) + type = "REG "; + if (S_ISLNK(mode)) + type = "LNK "; + if (S_ISDIR(mode)) + type = "DIR "; + if (S_ISCHR(mode)) + type = "CHR "; + if (S_ISBLK(mode)) + type = "BLK "; + if (S_ISFIFO(mode)) { + type = "FIFO"; + if (symbol_exists("pipe_inode_operations")) { + inode_i_op = ULONG(inode_buf + OFFSET(inode_i_op)); + if (inode_i_op == + symbol_value("pipe_inode_operations")) { + type = "PIPE"; + pathname[0] = NULLCHAR; + } + } else { + if (symbol_exists("rdwr_pipe_fops") && + (i_fop_off = OFFSET(inode_i_fop)) > 0) { + inode_i_fop = ULONG(inode_buf + i_fop_off); + if (inode_i_fop == + symbol_value("rdwr_pipe_fops")) { + type = "PIPE"; + pathname[0] = NULLCHAR; + } + } + } + } + if (S_ISSOCK(mode)) { + type = "SOCK"; + if (STREQ(pathname, "/")) + pathname[0] = NULLCHAR; + } + + return type; +} + + +/* + * Walk an open file list and return an array of open dentries. + */ +static ulong * +create_dentry_array(ulong list_addr, int *count) +{ + struct list_data list_data, *ld; + ulong *file, *files_list, *dentry_list; + ulong dentry, inode; + char *file_buf, *dentry_buf; + int cnt, f_count, i; + int dentry_cnt = 0; + + ld = &list_data; + BZERO(ld, sizeof(struct list_data)); + readmem(list_addr, KVADDR, &ld->start, sizeof(void *), "file list head", + FAULT_ON_ERROR); + + if (list_addr == ld->start) { /* empty list? */ + *count = 0; + return NULL; + } + + ld->end = list_addr; + hq_open(); + cnt = do_list(ld); + if (cnt == 0) { + hq_close(); + *count = 0; + return NULL; + } + files_list = (ulong *)GETBUF(cnt * sizeof(ulong)); + cnt = retrieve_list(files_list, cnt); + hq_close(); + hq_open(); + + for (i=0, file = files_list; i__per_cpu_offset[c]; + percpu_list[c].dentry_list = create_dentry_array(list_addr, + &percpu_list[c].count); + total += percpu_list[c].count; + } + + if (total) { + dentry_list = (ulong *)GETBUF(total * sizeof(ulong)); + + for (c = i = 0; c < (cpu+1); c++) { + if (percpu_list[c].count == 0) + continue; + for (j = 0; j < percpu_list[c].count; j++) + dentry_list[i++] = + percpu_list[c].dentry_list[j]; + FREEBUF(percpu_list[c].dentry_list); + } + } else + dentry_list = NULL; + + FREEBUF(percpu_list); + *count = total; + return dentry_list; +} + +/* + * Stash vfs structure offsets + */ +void +vfs_init(void) +{ + MEMBER_OFFSET_INIT(nlm_file_f_file, "nlm_file", "f_file"); + MEMBER_OFFSET_INIT(task_struct_files, "task_struct", "files"); + MEMBER_OFFSET_INIT(task_struct_fs, "task_struct", "fs"); + MEMBER_OFFSET_INIT(fs_struct_root, "fs_struct", "root"); + MEMBER_OFFSET_INIT(fs_struct_pwd, "fs_struct", "pwd"); + MEMBER_OFFSET_INIT(fs_struct_rootmnt, "fs_struct", "rootmnt"); + MEMBER_OFFSET_INIT(fs_struct_pwdmnt, "fs_struct", "pwdmnt"); + MEMBER_OFFSET_INIT(files_struct_open_fds_init, + "files_struct", "open_fds_init"); + MEMBER_OFFSET_INIT(files_struct_fdt, "files_struct", "fdt"); + if (VALID_MEMBER(files_struct_fdt)) { + MEMBER_OFFSET_INIT(fdtable_max_fds, "fdtable", "max_fds"); + MEMBER_OFFSET_INIT(fdtable_max_fdset, "fdtable", "max_fdset"); + MEMBER_OFFSET_INIT(fdtable_open_fds, "fdtable", "open_fds"); + MEMBER_OFFSET_INIT(fdtable_fd, "fdtable", "fd"); + } else { + MEMBER_OFFSET_INIT(files_struct_max_fds, "files_struct", "max_fds"); + MEMBER_OFFSET_INIT(files_struct_max_fdset, "files_struct", "max_fdset"); + MEMBER_OFFSET_INIT(files_struct_open_fds, "files_struct", "open_fds"); + MEMBER_OFFSET_INIT(files_struct_fd, "files_struct", "fd"); + } + MEMBER_OFFSET_INIT(file_f_dentry, "file", "f_dentry"); + MEMBER_OFFSET_INIT(file_f_vfsmnt, "file", "f_vfsmnt"); + MEMBER_OFFSET_INIT(file_f_count, "file", "f_count"); + MEMBER_OFFSET_INIT(path_mnt, "path", "mnt"); + MEMBER_OFFSET_INIT(path_dentry, "path", "dentry"); + if (INVALID_MEMBER(file_f_dentry)) { + MEMBER_OFFSET_INIT(file_f_path, "file", "f_path"); + ASSIGN_OFFSET(file_f_dentry) = OFFSET(file_f_path) + OFFSET(path_dentry); + ASSIGN_OFFSET(file_f_vfsmnt) = OFFSET(file_f_path) + OFFSET(path_mnt); + } + MEMBER_OFFSET_INIT(dentry_d_inode, "dentry", "d_inode"); + MEMBER_OFFSET_INIT(dentry_d_parent, "dentry", "d_parent"); + MEMBER_OFFSET_INIT(dentry_d_covers, "dentry", "d_covers"); + MEMBER_OFFSET_INIT(dentry_d_name, "dentry", "d_name"); + MEMBER_OFFSET_INIT(dentry_d_iname, "dentry", "d_iname"); + MEMBER_OFFSET_INIT(inode_i_mode, "inode", "i_mode"); + MEMBER_OFFSET_INIT(inode_i_op, "inode", "i_op"); + MEMBER_OFFSET_INIT(inode_i_sb, "inode", "i_sb"); + MEMBER_OFFSET_INIT(inode_u, "inode", "u"); + MEMBER_OFFSET_INIT(qstr_name, "qstr", "name"); + MEMBER_OFFSET_INIT(qstr_len, "qstr", "len"); + if (INVALID_MEMBER(qstr_len)) + ANON_MEMBER_OFFSET_INIT(qstr_len, "qstr", "len"); + + MEMBER_OFFSET_INIT(vfsmount_mnt_next, "vfsmount", "mnt_next"); + MEMBER_OFFSET_INIT(vfsmount_mnt_devname, "vfsmount", "mnt_devname"); + if (INVALID_MEMBER(vfsmount_mnt_devname)) + MEMBER_OFFSET_INIT(mount_mnt_devname, "mount", "mnt_devname"); + MEMBER_OFFSET_INIT(vfsmount_mnt_dirname, "vfsmount", "mnt_dirname"); + MEMBER_OFFSET_INIT(vfsmount_mnt_sb, "vfsmount", "mnt_sb"); + MEMBER_OFFSET_INIT(vfsmount_mnt_list, "vfsmount", "mnt_list"); + if (INVALID_MEMBER(vfsmount_mnt_devname)) + MEMBER_OFFSET_INIT(mount_mnt_list, "mount", "mnt_list"); + MEMBER_OFFSET_INIT(vfsmount_mnt_parent, "vfsmount", "mnt_parent"); + if (INVALID_MEMBER(vfsmount_mnt_devname)) + MEMBER_OFFSET_INIT(mount_mnt_parent, "mount", "mnt_parent"); + MEMBER_OFFSET_INIT(vfsmount_mnt_mountpoint, + "vfsmount", "mnt_mountpoint"); + if (INVALID_MEMBER(vfsmount_mnt_devname)) + MEMBER_OFFSET_INIT(mount_mnt_mountpoint, + "mount", "mnt_mountpoint"); + MEMBER_OFFSET_INIT(mount_mnt, "mount", "mnt"); + MEMBER_OFFSET_INIT(namespace_root, "namespace", "root"); + MEMBER_OFFSET_INIT(task_struct_nsproxy, "task_struct", "nsproxy"); + if (VALID_MEMBER(namespace_root)) { + MEMBER_OFFSET_INIT(namespace_list, "namespace", "list"); + MEMBER_OFFSET_INIT(task_struct_namespace, + "task_struct", "namespace"); + } else if (VALID_MEMBER(task_struct_nsproxy)) { + MEMBER_OFFSET_INIT(nsproxy_mnt_ns, "nsproxy", "mnt_ns"); + MEMBER_OFFSET_INIT(mnt_namespace_root, "mnt_namespace", "root"); + MEMBER_OFFSET_INIT(mnt_namespace_list, "mnt_namespace", "list"); + } else if (THIS_KERNEL_VERSION >= LINUX(2,4,20)) { + if (CRASHDEBUG(2)) + fprintf(fp, "hardwiring namespace stuff\n"); + ASSIGN_OFFSET(task_struct_namespace) = OFFSET(task_struct_files) + + sizeof(void *); + ASSIGN_OFFSET(namespace_root) = sizeof(void *); + ASSIGN_OFFSET(namespace_list) = sizeof(void *) * 2; + } + + MEMBER_OFFSET_INIT(super_block_s_dirty, "super_block", "s_dirty"); + MEMBER_OFFSET_INIT(super_block_s_type, "super_block", "s_type"); + MEMBER_OFFSET_INIT(file_system_type_name, "file_system_type", "name"); + MEMBER_OFFSET_INIT(super_block_s_files, "super_block", "s_files"); + MEMBER_OFFSET_INIT(inode_i_flock, "inode", "i_flock"); + MEMBER_OFFSET_INIT(file_lock_fl_owner, "file_lock", "fl_owner"); + MEMBER_OFFSET_INIT(nlm_host_h_exportent, "nlm_host", "h_exportent"); + MEMBER_OFFSET_INIT(svc_client_cl_ident, "svc_client", "cl_ident"); + MEMBER_OFFSET_INIT(inode_i_fop, "inode","i_fop"); + + STRUCT_SIZE_INIT(umode_t, "umode_t"); + STRUCT_SIZE_INIT(dentry, "dentry"); + STRUCT_SIZE_INIT(files_struct, "files_struct"); + if (VALID_MEMBER(files_struct_fdt)) + STRUCT_SIZE_INIT(fdtable, "fdtable"); + STRUCT_SIZE_INIT(file, "file"); + STRUCT_SIZE_INIT(inode, "inode"); + STRUCT_SIZE_INIT(mount, "mount"); + STRUCT_SIZE_INIT(vfsmount, "vfsmount"); + STRUCT_SIZE_INIT(fs_struct, "fs_struct"); + STRUCT_SIZE_INIT(super_block, "super_block"); + + if (!(ft->file_cache = (char *)malloc(SIZE(file)*FILE_CACHE))) + error(FATAL, "cannot malloc file cache\n"); + if (!(ft->dentry_cache = (char *)malloc(SIZE(dentry)*DENTRY_CACHE))) + error(FATAL, "cannot malloc dentry cache\n"); + if (!(ft->inode_cache = (char *)malloc(SIZE(inode)*INODE_CACHE))) + error(FATAL, "cannot malloc inode cache\n"); + + if (symbol_exists("height_to_maxindex")) { + int tmp ATTRIBUTE_UNUSED; + if (LKCD_KERNTYPES()) + ARRAY_LENGTH_INIT_ALT(tmp, "height_to_maxindex", + "radix_tree_preload.nodes", NULL, 0); + else + ARRAY_LENGTH_INIT(tmp, height_to_maxindex, + "height_to_maxindex", NULL, 0); + STRUCT_SIZE_INIT(radix_tree_root, "radix_tree_root"); + STRUCT_SIZE_INIT(radix_tree_node, "radix_tree_node"); + MEMBER_OFFSET_INIT(radix_tree_root_height, + "radix_tree_root","height"); + MEMBER_OFFSET_INIT(radix_tree_root_rnode, + "radix_tree_root","rnode"); + MEMBER_OFFSET_INIT(radix_tree_node_slots, + "radix_tree_node","slots"); + MEMBER_OFFSET_INIT(radix_tree_node_height, + "radix_tree_node","height"); + } + MEMBER_OFFSET_INIT(rb_root_rb_node, + "rb_root","rb_node"); + MEMBER_OFFSET_INIT(rb_node_rb_left, + "rb_node","rb_left"); + MEMBER_OFFSET_INIT(rb_node_rb_right, + "rb_node","rb_right"); +} + +void +dump_filesys_table(int verbose) +{ + int i; + ulong fhits, dhits, ihits; + + if (!verbose) + goto show_hit_rates; + + for (i = 0; i < FILE_CACHE; i++) + fprintf(fp, " cached_file[%2d]: %lx (%ld)\n", + i, ft->cached_file[i], + ft->cached_file_hits[i]); + fprintf(fp, " file_cache: %lx\n", (ulong)ft->file_cache); + fprintf(fp, " file_cache_index: %d\n", ft->file_cache_index); + fprintf(fp, " file_cache_fills: %ld\n", ft->file_cache_fills); + + for (i = 0; i < DENTRY_CACHE; i++) + fprintf(fp, " cached_dentry[%2d]: %lx (%ld)\n", + i, ft->cached_dentry[i], + ft->cached_dentry_hits[i]); + fprintf(fp, " dentry_cache: %lx\n", (ulong)ft->dentry_cache); + fprintf(fp, "dentry_cache_index: %d\n", ft->dentry_cache_index); + fprintf(fp, "dentry_cache_fills: %ld\n", ft->dentry_cache_fills); + + for (i = 0; i < INODE_CACHE; i++) + fprintf(fp, " cached_inode[%2d]: %lx (%ld)\n", + i, ft->cached_inode[i], + ft->cached_inode_hits[i]); + fprintf(fp, " inode_cache: %lx\n", (ulong)ft->inode_cache); + fprintf(fp, " inode_cache_index: %d\n", ft->inode_cache_index); + fprintf(fp, " inode_cache_fills: %ld\n", ft->inode_cache_fills); + +show_hit_rates: + if (ft->file_cache_fills) { + for (i = fhits = 0; i < FILE_CACHE; i++) + fhits += ft->cached_file_hits[i]; + + fprintf(fp, " file hit rate: %2ld%% (%ld of %ld)\n", + (fhits * 100)/ft->file_cache_fills, + fhits, ft->file_cache_fills); + } + + if (ft->dentry_cache_fills) { + for (i = dhits = 0; i < DENTRY_CACHE; i++) + dhits += ft->cached_dentry_hits[i]; + + fprintf(fp, " dentry hit rate: %2ld%% (%ld of %ld)\n", + (dhits * 100)/ft->dentry_cache_fills, + dhits, ft->dentry_cache_fills); + } + + if (ft->inode_cache_fills) { + for (i = ihits = 0; i < INODE_CACHE; i++) + ihits += ft->cached_inode_hits[i]; + + fprintf(fp, " inode hit rate: %2ld%% (%ld of %ld)\n", + (ihits * 100)/ft->inode_cache_fills, + ihits, ft->inode_cache_fills); + } +} + +/* + * This command displays information about the open files of a context. + * For each open file descriptor the file descriptor number, a pointer + * to the file struct, pointer to the dentry struct, pointer to the inode + * struct, indication of file type and pathname are printed. + * The argument can be a task address or a PID number; if no args, the + * current context is used. + * If the flag -l is passed, any files held open in the kernel by the + * lockd server on behalf of an NFS client are displayed. + */ + +void +cmd_files(void) +{ + int c; + ulong value; + struct task_context *tc; + int subsequent; + struct reference reference, *ref; + char *refarg; + + ref = NULL; + refarg = NULL; + + while ((c = getopt(argcnt, args, "d:R:")) != EOF) { + switch(c) + { + case 'R': + if (ref) { + error(INFO, "only one -R option allowed\n"); + argerrs++; + } else { + ref = &reference; + BZERO(ref, sizeof(struct reference)); + ref->str = refarg = optarg; + } + break; + + case 'd': + value = htol(optarg, FAULT_ON_ERROR, NULL); + display_dentry_info(value); + return; + + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + if (!args[optind]) { + if (!ref) + print_task_header(fp, CURRENT_CONTEXT(), 0); + open_files_dump(CURRENT_TASK(), 0, ref); + return; + } + + subsequent = 0; + + while (args[optind]) { + + if (ref && subsequent) { + BZERO(ref, sizeof(struct reference)); + ref->str = refarg; + } + + switch (str_to_context(args[optind], &value, &tc)) + { + case STR_PID: + for (tc = pid_to_context(value); tc; tc = tc->tc_next) { + if (!ref) + print_task_header(fp, tc, subsequent); + open_files_dump(tc->task, 0, ref); + fprintf(fp, "\n"); + } + break; + + case STR_TASK: + if (!ref) + print_task_header(fp, tc, subsequent); + open_files_dump(tc->task, 0, ref); + break; + + case STR_INVALID: + error(INFO, "invalid task or pid value: %s\n", + args[optind]); + break; + } + + subsequent++; + optind++; + } +} + +#define FILES_REF_HEXNUM (0x1) +#define FILES_REF_DECNUM (0x2) +#define FILES_REF_FOUND (0x4) + +#define PRINT_FILE_REFERENCE() \ + if (!root_pwd_printed) { \ + print_task_header(fp, tc, 0); \ + fprintf(fp, "%s", root_pwd); \ + root_pwd_printed = TRUE; \ + } \ + if (!header_printed) { \ + fprintf(fp, "%s", files_header);\ + header_printed = TRUE; \ + } \ + fprintf(fp, "%s", buf4); \ + ref->cmdflags |= FILES_REF_FOUND; + +#define FILENAME_COMPONENT(P,C) \ + ((STREQ((P), "/") && STREQ((C), "/")) || \ + (!STREQ((C), "/") && strstr((P),(C)))) + + + +/* + * open_files_dump() does the work for cmd_files(). + */ + +void +open_files_dump(ulong task, int flags, struct reference *ref) +{ + struct task_context *tc; + ulong files_struct_addr; + ulong fdtable_addr = 0; + char *files_struct_buf, *fdtable_buf = NULL; + ulong fs_struct_addr; + char *dentry_buf, *fs_struct_buf; + char *ret ATTRIBUTE_UNUSED; + ulong root_dentry, pwd_dentry; + ulong root_inode, pwd_inode; + ulong vfsmnt; + int max_fdset = 0; + int max_fds = 0; + ulong open_fds_addr; + fd_set open_fds; + ulong fd; + ulong file; + ulong value; + int i, j, use_path; + int header_printed = 0; + char root_pathname[BUFSIZE]; + char pwd_pathname[BUFSIZE]; + char files_header[BUFSIZE]; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + char buf3[BUFSIZE]; + char buf4[BUFSIZE]; + char root_pwd[BUFSIZE]; + int root_pwd_printed = 0; + + BZERO(root_pathname, BUFSIZE); + BZERO(pwd_pathname, BUFSIZE); + files_struct_buf = GETBUF(SIZE(files_struct)); + if (VALID_STRUCT(fdtable)) + fdtable_buf = GETBUF(SIZE(fdtable)); + fill_task_struct(task); + + sprintf(files_header, " FD%s%s%s%s%s%s%sTYPE%sPATH\n", + space(MINSPACE), + mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "FILE"), + space(MINSPACE), + mkstring(buf2, VADDR_PRLEN, CENTER|LJUST, "DENTRY"), + space(MINSPACE), + mkstring(buf3, VADDR_PRLEN, CENTER|LJUST, "INODE"), + space(MINSPACE), + space(MINSPACE)); + + tc = task_to_context(task); + + if (ref) + ref->cmdflags = 0; + + fs_struct_addr = ULONG(tt->task_struct + OFFSET(task_struct_fs)); + + if (fs_struct_addr) { + fs_struct_buf = GETBUF(SIZE(fs_struct)); + readmem(fs_struct_addr, KVADDR, fs_struct_buf, SIZE(fs_struct), + "fs_struct buffer", FAULT_ON_ERROR); + + use_path = (MEMBER_TYPE("fs_struct", "root") == TYPE_CODE_STRUCT); + if (use_path) + root_dentry = ULONG(fs_struct_buf + OFFSET(fs_struct_root) + + OFFSET(path_dentry)); + else + root_dentry = ULONG(fs_struct_buf + OFFSET(fs_struct_root)); + + if (root_dentry) { + if (VALID_MEMBER(fs_struct_rootmnt)) { + vfsmnt = ULONG(fs_struct_buf + + OFFSET(fs_struct_rootmnt)); + get_pathname(root_dentry, root_pathname, + BUFSIZE, 1, vfsmnt); + } else if (use_path) { + vfsmnt = ULONG(fs_struct_buf + + OFFSET(fs_struct_root) + + OFFSET(path_mnt)); + get_pathname(root_dentry, root_pathname, + BUFSIZE, 1, vfsmnt); + } else { + get_pathname(root_dentry, root_pathname, + BUFSIZE, 1, 0); + } + } + + if (use_path) + pwd_dentry = ULONG(fs_struct_buf + OFFSET(fs_struct_pwd) + + OFFSET(path_dentry)); + else + pwd_dentry = ULONG(fs_struct_buf + OFFSET(fs_struct_pwd)); + + if (pwd_dentry) { + if (VALID_MEMBER(fs_struct_pwdmnt)) { + vfsmnt = ULONG(fs_struct_buf + + OFFSET(fs_struct_pwdmnt)); + get_pathname(pwd_dentry, pwd_pathname, + BUFSIZE, 1, vfsmnt); + } else if (use_path) { + vfsmnt = ULONG(fs_struct_buf + + OFFSET(fs_struct_pwd) + + OFFSET(path_mnt)); + get_pathname(pwd_dentry, pwd_pathname, + BUFSIZE, 1, vfsmnt); + + } else { + get_pathname(pwd_dentry, pwd_pathname, + BUFSIZE, 1, 0); + } + } + + if ((flags & PRINT_INODES) && root_dentry && pwd_dentry) { + dentry_buf = fill_dentry_cache(root_dentry); + root_inode = ULONG(dentry_buf + OFFSET(dentry_d_inode)); + dentry_buf = fill_dentry_cache(pwd_dentry); + pwd_inode = ULONG(dentry_buf + OFFSET(dentry_d_inode)); + fprintf(fp, "ROOT: %lx %s CWD: %lx %s\n", + root_inode, root_pathname, pwd_inode, + pwd_pathname); + } else if (ref) { + snprintf(root_pwd, sizeof(root_pwd), + "ROOT: %s CWD: %s \n", + root_pathname, pwd_pathname); + if (FILENAME_COMPONENT(root_pathname, ref->str) || + FILENAME_COMPONENT(pwd_pathname, ref->str)) { + print_task_header(fp, tc, 0); + fprintf(fp, "%s", root_pwd); + root_pwd_printed = TRUE; + ref->cmdflags |= FILES_REF_FOUND; + } + } else + fprintf(fp, "ROOT: %s CWD: %s\n", + root_pathname, pwd_pathname); + + FREEBUF(fs_struct_buf); + } + + files_struct_addr = ULONG(tt->task_struct + OFFSET(task_struct_files)); + + if (files_struct_addr) { + readmem(files_struct_addr, KVADDR, files_struct_buf, + SIZE(files_struct), "files_struct buffer", + FAULT_ON_ERROR); + + if (VALID_MEMBER(files_struct_max_fdset)) { + max_fdset = INT(files_struct_buf + + OFFSET(files_struct_max_fdset)); + + max_fds = INT(files_struct_buf + + OFFSET(files_struct_max_fds)); + } + } + + if (VALID_MEMBER(files_struct_fdt)) { + fdtable_addr = ULONG(files_struct_buf + OFFSET(files_struct_fdt)); + + if (fdtable_addr) { + readmem(fdtable_addr, KVADDR, fdtable_buf, + SIZE(fdtable), "fdtable buffer", FAULT_ON_ERROR); + if (VALID_MEMBER(fdtable_max_fdset)) + max_fdset = INT(fdtable_buf + + OFFSET(fdtable_max_fdset)); + else + max_fdset = -1; + max_fds = INT(fdtable_buf + + OFFSET(fdtable_max_fds)); + } + } + + if ((VALID_MEMBER(files_struct_fdt) && !fdtable_addr) || + !files_struct_addr || max_fdset == 0 || max_fds == 0) { + if (ref) { + if (ref->cmdflags & FILES_REF_FOUND) + fprintf(fp, "\n"); + } else + fprintf(fp, "No open files\n"); + if (fdtable_buf) + FREEBUF(fdtable_buf); + FREEBUF(files_struct_buf); + return; + } + + if (ref && IS_A_NUMBER(ref->str)) { + if (hexadecimal_only(ref->str, 0)) { + ref->hexval = htol(ref->str, FAULT_ON_ERROR, NULL); + ref->cmdflags |= FILES_REF_HEXNUM; + } else { + value = dtol(ref->str, FAULT_ON_ERROR, NULL); + if (value <= MAX(max_fdset, max_fds)) { + ref->decval = value; + ref->cmdflags |= FILES_REF_DECNUM; + } else { + ref->hexval = htol(ref->str, + FAULT_ON_ERROR, NULL); + ref->cmdflags |= FILES_REF_HEXNUM; + } + } + } + + if (VALID_MEMBER(fdtable_open_fds)) + open_fds_addr = ULONG(fdtable_buf + + OFFSET(fdtable_open_fds)); + else + open_fds_addr = ULONG(files_struct_buf + + OFFSET(files_struct_open_fds)); + + if (open_fds_addr) { + if (VALID_MEMBER(files_struct_open_fds_init) && + (open_fds_addr == (files_struct_addr + + OFFSET(files_struct_open_fds_init)))) + BCOPY(files_struct_buf + + OFFSET(files_struct_open_fds_init), + &open_fds, sizeof(fd_set)); + else + readmem(open_fds_addr, KVADDR, &open_fds, + sizeof(fd_set), "fdtable open_fds", + FAULT_ON_ERROR); + } + + if (VALID_MEMBER(fdtable_fd)) + fd = ULONG(fdtable_buf + OFFSET(fdtable_fd)); + else + fd = ULONG(files_struct_buf + OFFSET(files_struct_fd)); + + if (!open_fds_addr || !fd) { + if (ref && (ref->cmdflags & FILES_REF_FOUND)) + fprintf(fp, "\n"); + if (fdtable_buf) + FREEBUF(fdtable_buf); + FREEBUF(files_struct_buf); + return; + } + + j = 0; + for (;;) { + unsigned long set; + i = j * __NFDBITS; + if (((max_fdset >= 0) && (i >= max_fdset)) || + (i >= max_fds)) + break; + set = open_fds.__fds_bits[j++]; + while (set) { + if (set & 1) { + readmem(fd + i*sizeof(struct file *), KVADDR, + &file, sizeof(struct file *), + "fd file", FAULT_ON_ERROR); + + if (ref && file) { + open_tmpfile(); + if (file_dump(file, 0, 0, i, + DUMP_FULL_NAME|DUMP_EMPTY_FILE)) { + BZERO(buf4, BUFSIZE); + rewind(pc->tmpfile); + ret = fgets(buf4, BUFSIZE, + pc->tmpfile); + close_tmpfile(); + ref->refp = buf4; + if (open_file_reference(ref)) { + PRINT_FILE_REFERENCE(); + } + } else + close_tmpfile(); + } + else if (file) { + if (!header_printed) { + fprintf(fp, "%s", files_header); + header_printed = 1; + } + file_dump(file, 0, 0, i, + DUMP_FULL_NAME|DUMP_EMPTY_FILE); + } + } + i++; + set >>= 1; + } + } + + if (!header_printed && !ref) + fprintf(fp, "No open files\n"); + + if (ref && (ref->cmdflags & FILES_REF_FOUND)) + fprintf(fp, "\n"); + + if (fdtable_buf) + FREEBUF(fdtable_buf); + FREEBUF(files_struct_buf); +} + +/* + * Check an open file string for references. + */ +static int +open_file_reference(struct reference *ref) +{ + char buf[BUFSIZE]; + char *arglist[MAXARGS]; + int i, fd, argcnt; + ulong vaddr; + + strcpy(buf, ref->refp); + if ((argcnt = parse_line(buf, arglist)) < 5) + return FALSE; + + if (ref->cmdflags & (FILES_REF_HEXNUM|FILES_REF_DECNUM)) { + fd = dtol(arglist[0], FAULT_ON_ERROR, NULL); + if (((ref->cmdflags & FILES_REF_HEXNUM) && + (fd == ref->hexval)) || + ((ref->cmdflags & FILES_REF_DECNUM) && + (fd == ref->decval))) { + return TRUE; + } + + for (i = 1; i < 4; i++) { + if (STREQ(arglist[i], "?")) + continue; + vaddr = htol(arglist[i], FAULT_ON_ERROR, NULL); + if (vaddr == ref->hexval) + return TRUE; + } + } + + if (STREQ(ref->str, arglist[4])) { + return TRUE; + } + + if ((argcnt == 6) && FILENAME_COMPONENT(arglist[5], ref->str)) { + return TRUE; + } + + return FALSE; +} + +#ifdef DEPRECATED +/* + * nlm_files_dump() prints files held open by lockd server on behalf + * of NFS clients + */ + +#define FILE_NRHASH 32 + +char nlm_files_header[BUFSIZE] = { 0 }; +char *nlm_header = \ +"Files open by lockd for client discretionary file locks:\n"; + +void +nlm_files_dump(void) +{ + int header_printed = 0; + int i, j, cnt; + ulong nlmsvc_ops, nlm_files; + struct syment *nsp; + ulong nlm_files_array[FILE_NRHASH]; + struct list_data list_data, *ld; + ulong *file, *files_list; + ulong dentry, inode, flock, host, client; + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + + if (!strlen(nlm_files_header)) { + sprintf(nlm_files_header, + "CLIENT %s %s%sTYPE%sPATH\n", + mkstring(buf1, VADDR_PRLEN, CENTER|LJUST, "NLM_FILE"), + mkstring(buf2, VADDR_PRLEN, CENTER|LJUST, "INODE"), + space(MINSPACE), + space(MINSPACE)); + } + + if (!symbol_exists("nlm_files") || !symbol_exists("nlmsvc_ops") + || !symbol_exists("nfsd_nlm_ops")) { + goto out; + } + get_symbol_data("nlmsvc_ops", sizeof(void *), &nlmsvc_ops); + if (nlmsvc_ops != symbol_value("nfsd_nlm_ops")) { + goto out; + } + if ((nsp = next_symbol("nlm_files", NULL)) == NULL) { + error(WARNING, "cannot find next symbol after nlm_files\n"); + goto out; + } + nlm_files = symbol_value("nlm_files"); + if (((nsp->value - nlm_files) / sizeof(void *)) != FILE_NRHASH ) { + error(WARNING, "FILE_NRHASH has changed from %d\n", + FILE_NRHASH); + if (((nsp->value - nlm_files) / sizeof(void *)) < + FILE_NRHASH ) + goto out; + } + + readmem(nlm_files, KVADDR, nlm_files_array, + sizeof(ulong) * FILE_NRHASH, "nlm_files array", + FAULT_ON_ERROR); + for (i = 0; i < FILE_NRHASH; i++) { + if (nlm_files_array[i] == 0) { + continue; + } + ld = &list_data; + BZERO(ld, sizeof(struct list_data)); + ld->start = nlm_files_array[i]; + hq_open(); + cnt = do_list(ld); + files_list = (ulong *)GETBUF(cnt * sizeof(ulong)); + cnt = retrieve_list(files_list, cnt); + hq_close(); + for (j=0, file = files_list; j 1 || !STREQ(buf, "/")) && + !STRNEQ(tmpname, "/")) { + sprintf(pathname, "%s%s%s", buf, + "/", tmpname); + } else { + sprintf(pathname, + "%s%s", buf, tmpname); + } + } + } else { + strncpy(pathname, buf, BUFSIZE); + } + + parent = ULONG(dentry_buf + OFFSET(dentry_d_parent)); + + if (tmp_dentry == parent && full) { + if (VALID_MEMBER(vfsmount_mnt_mountpoint)) { + if (tmp_vfsmnt) { + if (strncmp(pathname, "//", 2) == 0) + shift_string_left(pathname, 1); + readmem(tmp_vfsmnt, KVADDR, vfsmnt_buf, + SIZE(vfsmount), + "vfsmount buffer", + FAULT_ON_ERROR); + parent = ULONG(vfsmnt_buf + + OFFSET(vfsmount_mnt_mountpoint)); + mnt_parent = ULONG(vfsmnt_buf + + OFFSET(vfsmount_mnt_parent)); + if (tmp_vfsmnt == mnt_parent) + break; + else + tmp_vfsmnt = mnt_parent; + } + } else if (VALID_STRUCT(mount)) { + if (tmp_vfsmnt) { + if (strncmp(pathname, "//", 2) == 0) + shift_string_left(pathname, 1); + readmem(tmp_vfsmnt - OFFSET(mount_mnt), + KVADDR, mnt_buf, + SIZE(mount), + "mount buffer", + FAULT_ON_ERROR); + parent = ULONG(mnt_buf + + OFFSET(mount_mnt_mountpoint)); + mnt_parent = ULONG(mnt_buf + + OFFSET(mount_mnt_parent)); + if ((tmp_vfsmnt - OFFSET(mount_mnt)) == mnt_parent) + break; + else + tmp_vfsmnt = mnt_parent + OFFSET(mount_mnt); + } + } + else { + parent = ULONG(dentry_buf + + OFFSET(dentry_d_covers)); + } + } + + } while (tmp_dentry != parent && parent); + + if (mnt_buf) + FREEBUF(mnt_buf); + else if (vfsmnt_buf) + FREEBUF(vfsmnt_buf); +} + +/* + * If the pathname component, which may be internal or external to the + * dentry, has string length equal to what's expected, copy it into the + * passed-in buffer, and return its length. If it doesn't match, return 0. + */ +static int +get_pathname_component(ulong dentry, + ulong d_name_name, + int d_name_len, + char *dentry_buf, + char *pathbuf) +{ + int len = d_name_len; /* presume success */ + + if (d_name_name == (dentry + OFFSET(dentry_d_iname))) { + if (strlen(dentry_buf + OFFSET(dentry_d_iname)) == d_name_len) + strcpy(pathbuf, dentry_buf + OFFSET(dentry_d_iname)); + else + len = 0; + } else if ((read_string(d_name_name, pathbuf, BUFSIZE)) != d_name_len) + len = 0; + + return len; +} + +/* + * Cache the passed-in file structure. + */ +char * +fill_file_cache(ulong file) +{ + int i; + char *cache; + + ft->file_cache_fills++; + + for (i = 0; i < DENTRY_CACHE; i++) { + if (ft->cached_file[i] == file) { + ft->cached_file_hits[i]++; + cache = ft->file_cache + (SIZE(file)*i); + return(cache); + } + } + + cache = ft->file_cache + (SIZE(file)*ft->file_cache_index); + + readmem(file, KVADDR, cache, SIZE(file), + "fill_file_cache", FAULT_ON_ERROR); + + ft->cached_file[ft->file_cache_index] = file; + + ft->file_cache_index = (ft->file_cache_index+1) % DENTRY_CACHE; + + return(cache); +} + +/* + * If active, clear the file references. + */ +void +clear_file_cache(void) +{ + int i; + + if (DUMPFILE()) + return; + + for (i = 0; i < DENTRY_CACHE; i++) { + ft->cached_file[i] = 0; + ft->cached_file_hits[i] = 0; + } + + ft->file_cache_fills = 0; + ft->file_cache_index = 0; +} + + + +/* + * Cache the passed-in dentry structure. + */ +char * +fill_dentry_cache(ulong dentry) +{ + int i; + char *cache; + + ft->dentry_cache_fills++; + + for (i = 0; i < DENTRY_CACHE; i++) { + if (ft->cached_dentry[i] == dentry) { + ft->cached_dentry_hits[i]++; + cache = ft->dentry_cache + (SIZE(dentry)*i); + return(cache); + } + } + + cache = ft->dentry_cache + (SIZE(dentry)*ft->dentry_cache_index); + + readmem(dentry, KVADDR, cache, SIZE(dentry), + "fill_dentry_cache", FAULT_ON_ERROR); + + ft->cached_dentry[ft->dentry_cache_index] = dentry; + + ft->dentry_cache_index = (ft->dentry_cache_index+1) % DENTRY_CACHE; + + return(cache); +} + +/* + * If active, clear the dentry references. + */ +void +clear_dentry_cache(void) +{ + int i; + + if (DUMPFILE()) + return; + + for (i = 0; i < DENTRY_CACHE; i++) { + ft->cached_dentry[i] = 0; + ft->cached_dentry_hits[i] = 0; + } + + ft->dentry_cache_fills = 0; + ft->dentry_cache_index = 0; +} + +/* + * Cache the passed-in inode structure. + */ +char * +fill_inode_cache(ulong inode) +{ + int i; + char *cache; + + ft->inode_cache_fills++; + + for (i = 0; i < INODE_CACHE; i++) { + if (ft->cached_inode[i] == inode) { + ft->cached_inode_hits[i]++; + cache = ft->inode_cache + (SIZE(inode)*i); + return(cache); + } + } + + cache = ft->inode_cache + (SIZE(inode)*ft->inode_cache_index); + + readmem(inode, KVADDR, cache, SIZE(inode), + "fill_inode_cache", FAULT_ON_ERROR); + + ft->cached_inode[ft->inode_cache_index] = inode; + + ft->inode_cache_index = (ft->inode_cache_index+1) % INODE_CACHE; + + return(cache); +} + +/* + * If active, clear the inode references. + */ +void +clear_inode_cache(void) +{ + int i; + + if (DUMPFILE()) + return; + + for (i = 0; i < DENTRY_CACHE; i++) { + ft->cached_inode[i] = 0; + ft->cached_inode_hits[i] = 0; + } + + ft->inode_cache_fills = 0; + ft->inode_cache_index = 0; +} + + +/* + * This command displays the tasks using specified files or sockets. + * Tasks will be listed that reference the file as the current working + * directory, root directory, an open file descriptor, or that mmap the + * file. + * The argument can be a full pathname without symbolic links, or inode + * address. + */ + +void +cmd_fuser(void) +{ + int c; + char *spec_string, *tmp; + struct foreach_data foreach_data, *fd; + char task_buf[BUFSIZE]; + char buf[BUFSIZE]; + char uses[20]; + char fuser_header[BUFSIZE]; + int doing_fds, doing_mmap, len; + int fuser_header_printed, lockd_header_printed; + + while ((c = getopt(argcnt, args, "")) != EOF) { + switch(c) + { + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, SYNOPSIS); + + if (!args[optind]) { + cmd_usage(pc->curcmd, SYNOPSIS); + return; + } + + sprintf(fuser_header, " PID %s COMM USAGE\n", + mkstring(buf, VADDR_PRLEN, CENTER, "TASK")); + + doing_fds = doing_mmap = 0; + while (args[optind]) { + spec_string = args[optind]; + if (STRNEQ(spec_string, "0x") && hexadecimal(spec_string, 0)) + shift_string_left(spec_string, 2); + len = strlen(spec_string); + fuser_header_printed = 0; + lockd_header_printed = 0; + open_tmpfile(); + BZERO(&foreach_data, sizeof(struct foreach_data)); + fd = &foreach_data; + fd->keyword_array[0] = FOREACH_FILES; + fd->keyword_array[1] = FOREACH_VM; + fd->keys = 2; + fd->flags |= FOREACH_i_FLAG; + foreach(fd); + rewind(pc->tmpfile); + BZERO(uses, 20); + while (fgets(buf, BUFSIZE, pc->tmpfile)) { + if (STRNEQ(buf, "PID:")) { + if (!STREQ(uses, "")) { + if (!fuser_header_printed) { + fprintf(pc->saved_fp, + "%s", fuser_header); + fuser_header_printed = 1; + } + show_fuser(task_buf, uses); + BZERO(uses, 20); + } + BZERO(task_buf, BUFSIZE); + strcpy(task_buf, buf); + doing_fds = doing_mmap = 0; + continue; + } + if (STRNEQ(buf, "ROOT:")) { + if ((tmp = strstr(buf, spec_string)) && + (tmp[len] == ' ' || tmp[len] == '\n')) { + if (strstr(tmp, "CWD:")) { + strcat(uses, "root "); + if ((tmp = strstr(tmp+len, + spec_string)) && + (tmp[len] == ' ' || + tmp[len] == '\n')) { + strcat(uses, "cwd "); + } + } else { + strcat(uses, "cwd "); + } + } + continue; + } + if (strstr(buf, "DENTRY")) { + doing_fds = 1; + continue; + } + if (strstr(buf, "TOTAL_VM")) { + doing_fds = 0; + continue; + } + if (strstr(buf, " VMA ")) { + doing_mmap = 1; + doing_fds = 0; + continue; + } + if ((tmp = strstr(buf, spec_string)) && + (tmp[len] == ' ' || tmp[len] == '\n')) { + if (doing_fds) { + strcat(uses, "fd "); + doing_fds = 0; + } + if (doing_mmap) { + strcat(uses, "mmap "); + doing_mmap = 0; + } + } + + } + if (!STREQ(uses, "")) { + if (!fuser_header_printed) { + fprintf(pc->saved_fp, "%s", fuser_header); + fuser_header_printed = 1; + } + show_fuser(task_buf, uses); + BZERO(uses, 20); + } + close_tmpfile(); + optind++; + if (!fuser_header_printed && !lockd_header_printed) { + fprintf(fp, "No users of %s found\n", spec_string); + } + } +} + +static void +show_fuser(char *buf, char *uses) +{ + char pid[10]; + char task[20]; + char command[20]; + char *p; + int i; + + BZERO(pid, 10); + BZERO(task, 20); + BZERO(command, 20); + p = strstr(buf, "PID: ") + strlen("PID: "); + i = 0; + while (*p != ' ' && i < 10) { + pid[i++] = *p++; + } + pid[i] = NULLCHAR; + + p = strstr(buf, "TASK: ") + strlen("TASK: "); + while (*p == ' ') + p++; + i = 0; + while (*p != ' ' && i < 20) { + task[i++] = *p++; + } + task[i] = NULLCHAR; + mkstring(task, VADDR_PRLEN, RJUST, task); + + p = strstr(buf, "COMMAND: ") + strlen("COMMAND: "); + strncpy(command, p, 16); + i = strlen(command) - 1; + while (i < 16) { + command[i++] = ' '; + } + command[16] = NULLCHAR; + + fprintf(pc->saved_fp, "%5s %s %s %s\n", + pid, task, command, uses); +} + + +/* + * Gather some host memory/swap statistics, passing back whatever the + * caller requires. + */ + +int +monitor_memory(long *freemem_pages, + long *freeswap_pages, + long *mem_usage, + long *swap_usage) +{ + FILE *mp; + char buf[BUFSIZE]; + char *arglist[MAXARGS]; + int argc ATTRIBUTE_UNUSED; + int params; + ulong freemem, memtotal, freeswap, swaptotal; + + if (!file_exists("/proc/meminfo", NULL)) + return FALSE; + + if ((mp = fopen("/proc/meminfo", "r")) == NULL) + return FALSE; + + params = 0; + freemem = memtotal = freeswap = swaptotal = 0; + + while (fgets(buf, BUFSIZE, mp)) { + if (strstr(buf, "SwapFree")) { + params++; + argc = parse_line(buf, arglist); + if (decimal(arglist[1], 0)) + freeswap = (atol(arglist[1]) * 1024)/PAGESIZE(); + } + + if (strstr(buf, "MemFree")) { + params++; + argc = parse_line(buf, arglist); + if (decimal(arglist[1], 0)) + freemem = (atol(arglist[1]) * 1024)/PAGESIZE(); + } + + if (strstr(buf, "MemTotal")) { + params++; + argc = parse_line(buf, arglist); + if (decimal(arglist[1], 0)) + memtotal = (atol(arglist[1]) * 1024)/PAGESIZE(); + } + + if (strstr(buf, "SwapTotal")) { + params++; + argc = parse_line(buf, arglist); + if (decimal(arglist[1], 0)) + swaptotal = (atol(arglist[1]) * 1024)/PAGESIZE(); + } + + } + + fclose(mp); + + if (params != 4) + return FALSE; + + if (freemem_pages) + *freemem_pages = freemem; + if (freeswap_pages) + *freeswap_pages = freeswap; + if (mem_usage) + *mem_usage = ((memtotal-freemem)*100) / memtotal; + if (swap_usage) + *swap_usage = ((swaptotal-freeswap)*100) / swaptotal; + + return TRUE; +} + +/* + * Determine whether two filenames reference the same file. + */ +int +same_file(char *f1, char *f2) +{ + struct stat stat1, stat2; + + if ((stat(f1, &stat1) != 0) || (stat(f2, &stat2) != 0)) + return FALSE; + + if ((stat1.st_dev == stat2.st_dev) && + (stat1.st_ino == stat2.st_ino)) + return TRUE; + + return FALSE; +} + + +/* + * Determine which live memory source to use. + */ + +#define MODPROBE_CMD "/sbin/modprobe -l --type drivers/char 2>&1" + +static void +get_live_memory_source(void) +{ + FILE *pipe; + char buf[BUFSIZE]; + char modname1[BUFSIZE]; + char modname2[BUFSIZE]; + char *name; + int use_module, crashbuiltin; + struct stat stat1, stat2; + struct utsname utsname; + + if (!(pc->flags & PROC_KCORE)) + pc->flags |= DEVMEM; + if (pc->live_memsrc) + goto live_report; + + pc->live_memsrc = "/dev/mem"; + use_module = crashbuiltin = FALSE; + + if (file_exists("/dev/mem", &stat1) && + file_exists(pc->memory_device, &stat2) && + S_ISCHR(stat1.st_mode) && S_ISCHR(stat2.st_mode) && + (stat1.st_rdev == stat2.st_rdev)) { + if (!STREQ(pc->memory_device, "/dev/mem")) + error(INFO, "%s: same device as /dev/mem\n%s", + pc->memory_device, + pc->memory_module ? "" : "\n"); + if (pc->memory_module) + error(INFO, "ignoring --memory_module %s request\n\n", + pc->memory_module); + } else if (pc->memory_module && memory_driver_module_loaded(NULL)) { + error(INFO, "using pre-loaded \"%s\" module\n\n", + pc->memory_module); + pc->flags |= MODPRELOAD; + use_module = TRUE; + } else { + pc->memory_module = MEMORY_DRIVER_MODULE; + + if ((pipe = popen(MODPROBE_CMD, "r")) == NULL) { + error(INFO, "%s: %s\n", MODPROBE_CMD, strerror(errno)); + return; + } + + sprintf(modname1, "%s.o", pc->memory_module); + sprintf(modname2, "%s.ko", pc->memory_module); + while (fgets(buf, BUFSIZE, pipe)) { + if (strstr(buf, "invalid option") && + (uname(&utsname) == 0)) { + sprintf(buf, + "/lib/modules/%s/kernel/drivers/char/%s", + utsname.release, modname2); + if (file_exists(buf, &stat1)) + use_module = TRUE; + break; + } + name = basename(strip_linefeeds(buf)); + if (STREQ(name, modname1) || STREQ(name, modname2)) { + use_module = TRUE; + break; + } + } + + pclose(pipe); + + if (!use_module && file_exists("/dev/crash", &stat1) && + S_ISCHR(stat1.st_mode)) + crashbuiltin = TRUE; + } + + if (use_module) { + pc->flags &= ~DEVMEM; + pc->flags |= MEMMOD; + pc->readmem = read_memory_device; + pc->writemem = write_memory_device; + pc->live_memsrc = pc->memory_device; + } + + if (crashbuiltin) { + pc->flags &= ~DEVMEM; + pc->flags |= CRASHBUILTIN; + pc->readmem = read_memory_device; + pc->writemem = write_memory_device; + pc->live_memsrc = pc->memory_device; + pc->memory_module = NULL; + } + +live_report: + if (CRASHDEBUG(1)) + fprintf(fp, "get_live_memory_source: %s\n", pc->live_memsrc); +} + +/* + * Read /proc/modules to determine whether the crash driver module + * has been loaded. + */ +static int +memory_driver_module_loaded(int *count) +{ + FILE *modules; + int argcnt, module_loaded; + char *arglist[MAXARGS]; + char buf[BUFSIZE]; + + if ((modules = fopen("/proc/modules", "r")) == NULL) { + error(INFO, "/proc/modules: %s\n", strerror(errno)); + return FALSE; + } + + module_loaded = FALSE; + while (fgets(buf, BUFSIZE, modules)) { + console("%s", buf); + argcnt = parse_line(buf, arglist); + if (argcnt < 3) + continue; + if (STREQ(arglist[0], pc->memory_module)) { + module_loaded = TRUE; + if (CRASHDEBUG(1)) + fprintf(stderr, + "\"%s\" module loaded: [%s][%s][%s]\n", + arglist[0], arglist[0], + arglist[1], arglist[2]); + if (count) + *count = atoi(arglist[2]); + break; + } + } + + fclose(modules); + + return module_loaded; +} + +/* + * Insmod the memory driver module. + */ +static int +insmod_memory_driver_module(void) +{ + FILE *pipe; + char buf[BUFSIZE]; + char command[BUFSIZE]; + + sprintf(command, "/sbin/modprobe %s", pc->memory_module); + if (CRASHDEBUG(1)) + fprintf(fp, "%s\n", command); + + if ((pipe = popen(command, "r")) == NULL) { + error(INFO, "%s: %s", command, strerror(errno)); + return FALSE; + } + + while (fgets(buf, BUFSIZE, pipe)) + fprintf(fp, "%s\n", buf); + pclose(pipe); + + if (!memory_driver_module_loaded(NULL)) { + error(INFO, "cannot insmod \"%s\" module\n", pc->memory_module); + return FALSE; + } + + return TRUE; +} + +/* + * Return the dev_t for the memory device driver. The major number will + * be that of the kernel's misc driver; the minor is dynamically created + * when the module at inmod time, and found in /proc/misc. + */ +static int +get_memory_driver_dev(dev_t *devp) +{ + char buf[BUFSIZE]; + char *arglist[MAXARGS]; + int argcnt; + FILE *misc; + int minor; + dev_t dev; + + dev = 0; + + if ((misc = fopen("/proc/misc", "r")) == NULL) { + error(INFO, "/proc/misc: %s", strerror(errno)); + } else { + while (fgets(buf, BUFSIZE, misc)) { + argcnt = parse_line(buf, arglist); + if ((argcnt == 2) && + STREQ(arglist[1], pc->memory_module)) { + minor = atoi(arglist[0]); + dev = makedev(MISC_MAJOR, minor); + if (CRASHDEBUG(1)) + fprintf(fp, + "/proc/misc: %s %s => %d/%d\n", + arglist[0], arglist[1], + major(dev), minor(dev)); + break; + } + } + fclose(misc); + } + + if (!dev) { + error(INFO, "cannot determine minor number of %s driver\n", + pc->memory_module); + return FALSE; + } + + *devp = dev; + return TRUE; +} + +/* + * Deal with the creation or verification of the memory device file: + * + * 1. If the device exists, and has the correct major/minor device numbers, + * nothing needs to be done. + * 2. If the filename exists, but it's not a device file, has the wrong + * major/minor device numbers, or the wrong permissions, advise the + * user to delete it. + * 3. Otherwise, create it. + */ +static int +create_memory_device(dev_t dev) +{ + struct stat stat; + + if (file_exists(pc->live_memsrc, &stat)) { + /* + * It already exists -- just use it. + */ + if ((stat.st_mode == MEMORY_DRIVER_DEVICE_MODE) && + (stat.st_rdev == dev)) + return TRUE; + + /* + * Either it's not a device special file, or it's got + * the wrong major/minor numbers, or the wrong permissions. + * Unlink the file -- it shouldn't be there. + */ + if (!S_ISCHR(stat.st_mode)) + error(FATAL, + "%s: not a character device -- please delete it!\n", + pc->live_memsrc); + else if (dev != stat.st_rdev) + error(FATAL, + "%s: invalid device: %d/%d -- please delete it!\n", + pc->live_memsrc, major(stat.st_rdev), + minor(stat.st_rdev)); + else + unlink(pc->live_memsrc); + } + + /* + * Either it doesn't exist or it was just unlinked. + * In either case, try to create it. + */ + if (mknod(pc->live_memsrc, MEMORY_DRIVER_DEVICE_MODE, dev)) { + error(INFO, "%s: mknod: %s\n", pc->live_memsrc, + strerror(errno)); + return FALSE; + } + + return TRUE; +} + +/* + * If we're here, the memory driver module is being requested: + * + * 1. If /dev/crash is built into the kernel, just open it. + * 2. If the module is not already loaded, insmod it. + * 3. Determine the misc driver minor device number that it was assigned. + * 4. Create (or verify) the device file. + * 5. Then just open it. + */ + +static int +memory_driver_init(void) +{ + dev_t dev; + + if (pc->flags & CRASHBUILTIN) + goto open_device; + + if (!memory_driver_module_loaded(NULL)) { + if (!insmod_memory_driver_module()) + return FALSE; + } else + pc->flags |= MODPRELOAD; + + if (!get_memory_driver_dev(&dev)) + return FALSE; + + if (!create_memory_device(dev)) + return FALSE; + +open_device: + if ((pc->mfd = open(pc->memory_device, O_RDONLY)) < 0) { + error(INFO, "%s: open: %s\n", pc->memory_device, + strerror(errno)); + return FALSE; + } + + return TRUE; +} + +/* + * Remove the memory driver module and associated file. + */ +int +cleanup_memory_driver(void) +{ + int errors, count; + char command[BUFSIZE]; + + count = errors = 0; + + if (pc->flags & KERNEL_DEBUG_QUERY) + return TRUE; + + close(pc->mfd); + if (file_exists(pc->memory_device, NULL) && + unlink(pc->memory_device)) { + error(INFO, "%s: %s\n", pc->memory_device, strerror(errno)); + errors++; + } + + if (!(pc->flags & MODPRELOAD) && + memory_driver_module_loaded(&count) && !count) { + sprintf(command, "/sbin/rmmod %s", pc->memory_module); + if (CRASHDEBUG(1)) + fprintf(fp, "%s\n", command); + errors += system(command); + } + + if (errors) + error(NOTE, "cleanup_memory_driver failed\n"); + + return errors ? FALSE : TRUE; +} + + +/* + * Use the kernel's radix_tree_lookup() function as a template to dump + * a radix tree's entries. + */ + +ulong RADIX_TREE_MAP_SHIFT = UNINITIALIZED; +ulong RADIX_TREE_MAP_SIZE = UNINITIALIZED; +ulong RADIX_TREE_MAP_MASK = UNINITIALIZED; + +/* + * do_radix_tree argument usage: + * + * root: Address of a radix_tree_root structure + * + * flag: RADIX_TREE_COUNT - Return the number of entries in the tree. + * RADIX_TREE_SEARCH - Search for an entry at rtp->index; if found, + * store the entry in rtp->value and return a count of 1; otherwise + * return a count of 0. + * RADIX_TREE_DUMP - Dump all existing index/value pairs. + * RADIX_TREE_GATHER - Store all existing index/value pairs in the + * passed-in array of radix_tree_pair structs starting at rtp, + * returning the count of entries stored; the caller can/should + * limit the number of returned entries by putting the array size + * (max count) in the rtp->index field of the first structure + * in the passed-in array. + * + * rtp: Unused by RADIX_TREE_COUNT and RADIX_TREE_DUMP. + * A pointer to a radix_tree_pair structure for RADIX_TREE_SEARCH. + * A pointer to an array of radix_tree_pair structures for + * RADIX_TREE_GATHER; the dimension (max count) of the array may + * be stored in the index field of the first structure to avoid + * any chance of an overrun. + */ +ulong +do_radix_tree(ulong root, int flag, struct radix_tree_pair *rtp) +{ + int i, ilen, height; + long nlen; + ulong index, maxindex, count, maxcount; + long *height_to_maxindex; + char *radix_tree_root_buf; + struct radix_tree_pair *r; + ulong root_rnode; + void *ret; + + count = 0; + + if (!VALID_STRUCT(radix_tree_root) || !VALID_STRUCT(radix_tree_node) || + !VALID_MEMBER(radix_tree_root_height) || + !VALID_MEMBER(radix_tree_root_rnode) || + !VALID_MEMBER(radix_tree_node_slots) || + !ARRAY_LENGTH(height_to_maxindex)) + error(FATAL, + "radix trees do not exist (or have changed their format)\n"); + + if (RADIX_TREE_MAP_SHIFT == UNINITIALIZED) { + if (!(nlen = MEMBER_SIZE("radix_tree_node", "slots"))) + error(FATAL, "cannot determine length of " + "radix_tree_node.slots[] array\n"); + nlen /= sizeof(void *); + RADIX_TREE_MAP_SHIFT = ffsl(nlen) - 1; + RADIX_TREE_MAP_SIZE = (1UL << RADIX_TREE_MAP_SHIFT); + RADIX_TREE_MAP_MASK = (RADIX_TREE_MAP_SIZE-1); + } + + ilen = ARRAY_LENGTH(height_to_maxindex); + height_to_maxindex = (long *)GETBUF(ilen * sizeof(long)); + readmem(symbol_value("height_to_maxindex"), KVADDR, + height_to_maxindex, ilen*sizeof(long), + "height_to_maxindex array", FAULT_ON_ERROR); + + if (CRASHDEBUG(1)) { + fprintf(fp, "radix_tree_node.slots[%ld]\n", + RADIX_TREE_MAP_SIZE); + fprintf(fp, "height_to_maxindex[%d]: ", ilen); + for (i = 0; i < ilen; i++) + fprintf(fp, "%lu ", height_to_maxindex[i]); + fprintf(fp, "\n"); + fprintf(fp, "radix_tree_root at %lx:\n", root); + dump_struct("radix_tree_root", (ulong)root, RADIX(16)); + } + + radix_tree_root_buf = GETBUF(SIZE(radix_tree_root)); + readmem(root, KVADDR, radix_tree_root_buf, SIZE(radix_tree_root), + "radix_tree_root", FAULT_ON_ERROR); + height = UINT(radix_tree_root_buf + OFFSET(radix_tree_root_height)); + + if (height > ilen) { + fprintf(fp, "radix_tree_root at %lx:\n", root); + dump_struct("radix_tree_root", (ulong)root, RADIX(16)); + error(FATAL, + "height %d is greater than height_to_maxindex[] index %ld\n", + height, ilen); + } + + maxindex = height_to_maxindex[height]; + FREEBUF(height_to_maxindex); + FREEBUF(radix_tree_root_buf); + + root_rnode = root + OFFSET(radix_tree_root_rnode); + + switch (flag) + { + case RADIX_TREE_COUNT: + for (index = count = 0; index <= maxindex; index++) { + if (radix_tree_lookup(root_rnode, index, height)) + count++; + } + break; + + case RADIX_TREE_SEARCH: + count = 0; + if (rtp->index > maxindex) + break; + + if ((ret = radix_tree_lookup(root_rnode, rtp->index, height))) { + rtp->value = ret; + count++; + } + break; + + case RADIX_TREE_DUMP: + for (index = count = 0; index <= maxindex; index++) { + if ((ret = + radix_tree_lookup(root_rnode, index, height))) { + fprintf(fp, "[%ld] %lx\n", index, (ulong)ret); + count++; + } + } + break; + + case RADIX_TREE_GATHER: + if (!(maxcount = rtp->index)) + maxcount = (ulong)(-1); /* caller beware */ + + for (index = count = 0, r = rtp; index <= maxindex; index++) { + if ((ret = + radix_tree_lookup(root_rnode, index, height))) { + r->index = index; + r->value = ret; + count++; + if (--maxcount <= 0) + break; + r++; + } + } + break; + + default: + error(FATAL, "do_radix_tree: invalid flag: %lx\n", flag); + } + + return count; +} + +static void * +radix_tree_lookup(ulong root_rnode, ulong index, int height) +{ + unsigned int shift; + ulong rnode; + ulong *slots; + + shift = (height-1) * RADIX_TREE_MAP_SHIFT; + + readmem(root_rnode, KVADDR, &rnode, sizeof(void *), + "radix_tree_root rnode", FAULT_ON_ERROR); + + if (rnode & 1) + rnode &= ~1; + + slots = (ulong *)GETBUF(sizeof(void *) * RADIX_TREE_MAP_SIZE); + + while (height > 0) { + if (rnode == 0) + break; + + readmem((ulong)rnode+OFFSET(radix_tree_node_slots), KVADDR, + &slots[0], sizeof(void *) * RADIX_TREE_MAP_SIZE, + "radix_tree_node.slots array", FAULT_ON_ERROR); + + rnode = slots[((index >> shift) & RADIX_TREE_MAP_MASK)]; + + shift -= RADIX_TREE_MAP_SHIFT; + height--; + } + + FREEBUF(slots); + + return (void *)rnode; +} + +int +is_readable(char *filename) +{ + int fd; + + if ((fd = open(filename, O_RDONLY)) < 0) { + error(INFO, "%s: %s\n", filename, strerror(errno)); + return FALSE; + } else + close(fd); + + return TRUE; +} + +static int +match_file_string(char *filename, char *string, char *buffer) +{ + int found; + char command[BUFSIZE]; + FILE *pipe; + + + sprintf(command, "/usr/bin/strings %s", filename); + if ((pipe = popen(command, "r")) == NULL) { + error(INFO, "%s: %s\n", filename, strerror(errno)); + return FALSE; + } + + found = FALSE; + while (fgets(buffer, BUFSIZE-1, pipe)) { + if (strstr(buffer, string)) { + found = TRUE; + break; + } + } + pclose(pipe); + + return found; +} + +char * +vfsmount_devname(ulong vfsmnt, char *buf, int maxlen) +{ + ulong devp; + + BZERO(buf, maxlen); + + if (VALID_STRUCT(mount)) { + if (!readmem(vfsmnt - OFFSET(mount_mnt) + OFFSET(mount_mnt_devname), + KVADDR, &devp, sizeof(void *), "mount mnt_devname", + QUIET|RETURN_ON_ERROR)) + return buf; + } else { + if (!readmem(vfsmnt + OFFSET(vfsmount_mnt_devname), + KVADDR, &devp, sizeof(void *), "vfsmount mnt_devname", + QUIET|RETURN_ON_ERROR)) + return buf; + } + + if (read_string(devp, buf, BUFSIZE-1)) + return buf; + + return buf; +} + +static ulong +get_root_vfsmount(char *file_buf) +{ + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + ulong vfsmnt; + ulong mnt_parent; + + vfsmnt = ULONG(file_buf + OFFSET(file_f_vfsmnt)); + + if (!strlen(vfsmount_devname(vfsmnt, buf1, BUFSIZE))) + return vfsmnt; + + if (STREQ(buf1, "udev") || STREQ(buf1, "devtmpfs")) { + if (VALID_STRUCT(mount)) { + if (!readmem(vfsmnt - OFFSET(mount_mnt) + OFFSET(mount_mnt_parent), KVADDR, + &mnt_parent, sizeof(void *), "mount mnt_parent", + QUIET|RETURN_ON_ERROR)) + return vfsmnt; + } else { + if (!readmem(vfsmnt + OFFSET(vfsmount_mnt_parent), KVADDR, + &mnt_parent, sizeof(void *), "vfsmount mnt_parent", + QUIET|RETURN_ON_ERROR)) + return vfsmnt; + } + + if (!strlen(vfsmount_devname(mnt_parent, buf2, BUFSIZE))) + return vfsmnt; + + if (STREQ(buf1, "udev") && STREQ(buf2, "udev")) + return mnt_parent; + if (STREQ(buf1, "devtmpfs") && STREQ(buf2, "devtmpfs")) + return mnt_parent; + } + + return vfsmnt; +} diff --git a/gdb-7.6.patch b/gdb-7.6.patch new file mode 100644 index 00000000..09543c0f --- /dev/null +++ b/gdb-7.6.patch @@ -0,0 +1,1563 @@ +--- gdb-7.6/libiberty/Makefile.in.orig ++++ gdb-7.6/libiberty/Makefile.in +@@ -175,6 +175,7 @@ REQUIRED_OFILES = \ + ./getruntime.$(objext) ./hashtab.$(objext) ./hex.$(objext) \ + ./lbasename.$(objext) ./lrealpath.$(objext) \ + ./make-relative-prefix.$(objext) ./make-temp-file.$(objext) \ ++ ./mkstemps.$(objext) \ + ./objalloc.$(objext) \ + ./obstack.$(objext) \ + ./partition.$(objext) ./pexecute.$(objext) ./physmem.$(objext) \ +@@ -206,7 +207,7 @@ CONFIGURED_OFILES = ./asprintf.$(objext) + ./index.$(objext) ./insque.$(objext) \ + ./memchr.$(objext) ./memcmp.$(objext) ./memcpy.$(objext) \ + ./memmem.$(objext) ./memmove.$(objext) \ +- ./mempcpy.$(objext) ./memset.$(objext) ./mkstemps.$(objext) \ ++ ./mempcpy.$(objext) ./memset.$(objext) \ + ./pex-djgpp.$(objext) ./pex-msdos.$(objext) \ + ./pex-unix.$(objext) ./pex-win32.$(objext) \ + ./putenv.$(objext) \ +--- gdb-7.6/opcodes/i386-dis.c.orig ++++ gdb-7.6/opcodes/i386-dis.c +@@ -11510,6 +11510,10 @@ print_insn (bfd_vma pc, disassemble_info + threebyte = *++codep; + dp = &dis386_twobyte[threebyte]; + need_modrm = twobyte_has_modrm[*codep]; ++ if (dp->name && ((strcmp(dp->name, "ud2a") == 0) || (strcmp(dp->name, "ud2") == 0))) { ++ extern int kernel_BUG_encoding_bytes(void); ++ codep += kernel_BUG_encoding_bytes(); ++ } + codep++; + } + else +--- gdb-7.6/gdb/dwarf2read.c.orig ++++ gdb-7.6/gdb/dwarf2read.c +@@ -2670,7 +2670,11 @@ read_index_from_section (struct objfile + indices. */ + if (version < 4) + { ++#ifdef CRASH_MERGE ++ static int warning_printed = 1; ++#else + static int warning_printed = 0; ++#endif + if (!warning_printed) + { + warning (_("Skipping obsolete .gdb_index section in %s."), +@@ -2689,7 +2693,11 @@ read_index_from_section (struct objfile + "set use-deprecated-index-sections on". */ + if (version < 6 && !deprecated_ok) + { ++#ifdef CRASH_MERGE ++ static int warning_printed = 1; ++#else + static int warning_printed = 0; ++#endif + if (!warning_printed) + { + warning (_("\ +--- gdb-7.6/gdb/amd64-linux-nat.c.orig ++++ gdb-7.6/gdb/amd64-linux-nat.c +@@ -45,6 +45,17 @@ + /* ezannoni-2003-07-09: I think this is fixed. The extraneous defs have + been removed from ptrace.h in the kernel. However, better safe than + sorry. */ ++#ifdef CRASH_MERGE ++/* ++ * When compiling within a 2.6.25-based Fedora build environment with ++ * gcc 4.3, four new "typedef unsigned int u32;" declarations were ++ * required due to a new ptrace_bts_config structure declaration in ++ * "asm-x86/ptrace-abi.h" that used u32 members, but u32 is defined in ++ * "asm-x86/types.h" within a __KERNEL__ section. They've been changed ++ * to __u32, but this patch remains for building in that environment. ++ */ ++typedef unsigned int u32; ++#endif + #include + #include + #include "gdb_proc_service.h" +--- gdb-7.6/gdb/symfile.c.orig ++++ gdb-7.6/gdb/symfile.c +@@ -693,7 +693,26 @@ default_symfile_offsets (struct objfile + for (cur_sec = abfd->sections; cur_sec != NULL; cur_sec = cur_sec->next) + /* We do not expect this to happen; just skip this step if the + relocatable file has a section with an assigned VMA. */ +- if (bfd_section_vma (abfd, cur_sec) != 0) ++ if (bfd_section_vma (abfd, cur_sec) != 0 ++ /* ++ * Kernel modules may have some non-zero VMAs, i.e., like the ++ * __ksymtab and __ksymtab_gpl sections in this example: ++ * ++ * Section Headers: ++ * [Nr] Name Type Address Offset ++ * Size EntSize Flags Link Info Align ++ * ... ++ * [ 8] __ksymtab PROGBITS 0000000000000060 0000ad90 ++ * 0000000000000010 0000000000000000 A 0 0 16 ++ * [ 9] .rela__ksymtab RELA 0000000000000000 0000ada0 ++ * 0000000000000030 0000000000000018 43 8 8 ++ * [10] __ksymtab_gpl PROGBITS 0000000000000070 0000add0 ++ * 00000000000001a0 0000000000000000 A 0 0 16 ++ * ... ++ * ++ * but they should be treated as if they are NULL. ++ */ ++ && strncmp (bfd_get_section_name (abfd, cur_sec), "__k", 3) != 0) + break; + + if (cur_sec == NULL) +@@ -1122,6 +1141,12 @@ symbol_file_add_with_addrs_or_offsets (b + error (_("Not confirmed.")); + + objfile = allocate_objfile (abfd, flags | (mainline ? OBJF_MAINLINE : 0)); ++#ifdef CRASH_MERGE ++ if (add_flags & SYMFILE_MAINLINE) { ++ extern struct objfile *gdb_kernel_objfile; ++ gdb_kernel_objfile = objfile; ++ } ++#endif + + if (parent) + add_separate_debug_objfile (objfile, parent); +@@ -1484,6 +1509,9 @@ find_separate_debug_file (const char *di + VEC (char_ptr) *debugdir_vec; + struct cleanup *back_to; + int ix; ++#ifdef CRASH_MERGE ++ extern int check_specified_module_tree(char *, char *); ++#endif + + /* Set I to max (strlen (canon_dir), strlen (dir)). */ + i = strlen (dir); +@@ -1513,6 +1541,15 @@ find_separate_debug_file (const char *di + if (separate_debug_file_exists (debugfile, crc32, objfile)) + return debugfile; + ++#ifdef CRASH_MERGE ++{ ++ if (check_specified_module_tree(objfile->name, debugfile) && ++ separate_debug_file_exists(debugfile, crc32, objfile)) { ++ return debugfile; ++ } ++} ++#endif ++ + /* Then try in the global debugfile directories. + + Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will +@@ -1583,6 +1620,10 @@ find_separate_debug_file_by_debuglink (s + char *debugfile; + unsigned long crc32; + struct cleanup *cleanups; ++#ifdef CRASH_MERGE ++ char *name_copy; ++ extern char *check_specified_kernel_debug_file(); ++#endif + + debuglink = get_debug_link_info (objfile, &crc32); + +@@ -1635,6 +1676,12 @@ find_separate_debug_file_by_debuglink (s + } + + do_cleanups (cleanups); ++#ifdef CRASH_MERGE ++ if (debugfile == NULL) { ++ name_copy = check_specified_kernel_debug_file(); ++ return (name_copy ? xstrdup(name_copy) : NULL); ++ } ++#endif + return debugfile; + } + +@@ -2409,8 +2456,10 @@ add_symbol_file_command (char *args, int + so we can't determine what section names are valid. */ + } + ++#ifndef CRASH_MERGE + if (from_tty && (!query ("%s", ""))) + error (_("Not confirmed.")); ++#endif + + symbol_file_add (filename, from_tty ? SYMFILE_VERBOSE : 0, + section_addrs, flags); +@@ -3690,6 +3739,15 @@ bfd_byte * + symfile_relocate_debug_section (struct objfile *objfile, + asection *sectp, bfd_byte *buf) + { ++#ifdef CRASH_MERGE ++ /* Executable files have all the relocations already resolved. ++ * Handle files linked with --emit-relocs. ++ * http://sources.redhat.com/ml/gdb/2006-08/msg00137.html ++ */ ++ bfd *abfd = objfile->obfd; ++ if ((abfd->flags & EXEC_P) != 0) ++ return NULL; ++#endif + gdb_assert (objfile->sf->sym_relocate); + + return (*objfile->sf->sym_relocate) (objfile, sectp, buf); +--- gdb-7.6/gdb/cli/cli-cmds.c.orig ++++ gdb-7.6/gdb/cli/cli-cmds.c +@@ -466,6 +466,10 @@ show_script_ext_mode (struct ui_file *fi + If SEARCH_PATH is non-zero, and the file isn't found in cwd, + search for it in the source search path. */ + ++#ifdef CRASH_MERGE ++static int crash_from_tty = 0; ++#endif ++ + int + find_and_open_script (const char *script_file, int search_path, + FILE **streamp, char **full_pathp) +@@ -508,6 +512,32 @@ find_and_open_script (const char *script + return 0; + } + ++#ifdef CRASH_MERGE ++ /* ++ * Only allow trusted versions of .gdbinit files to be ++ * sourced during session initialization. ++ */ ++ if (crash_from_tty == -1) ++ { ++ struct stat statbuf; ++ FILE *stream = *streamp; ++ int fd = fileno (stream); ++ if (fstat (fd, &statbuf) < 0) ++ { ++ perror_with_name (*full_pathp); ++ fclose (stream); ++ return 0; ++ } ++ if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH)) ++ { ++ extern void untrusted_file(FILE *, char *); ++ untrusted_file(NULL, *full_pathp); ++ fclose (stream); ++ return 0; ++ } ++ } ++#endif ++ + return 1; + } + +@@ -566,7 +596,11 @@ source_script_with_search (const char *f + If the source command was invoked interactively, throw an + error. Otherwise (e.g. if it was invoked by a script), + silently ignore the error. */ ++#ifdef CRASH_MERGE ++ if (from_tty > 0) ++#else + if (from_tty) ++#endif + perror_with_name (file); + else + return; +@@ -589,7 +623,14 @@ source_script_with_search (const char *f + void + source_script (char *file, int from_tty) + { ++#ifdef CRASH_MERGE ++ crash_from_tty = from_tty; ++#endif + source_script_with_search (file, from_tty, 0); ++#ifdef CRASH_MERGE ++ crash_from_tty = 0; ++#endif ++ + } + + /* Return the source_verbose global variable to its previous state +--- gdb-7.6/gdb/psymtab.c.orig ++++ gdb-7.6/gdb/psymtab.c +@@ -305,10 +305,14 @@ find_pc_sect_psymtab (struct objfile *ob + struct minimal_symbol *msymbol) + { + struct partial_symtab *pst; ++#ifdef CRASH_MERGE ++ extern int gdb_line_number_callback(unsigned long, unsigned long, unsigned long); ++#endif + + /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity + than the later used TEXTLOW/TEXTHIGH one. */ + ++#ifndef __i386__ + if (objfile->psymtabs_addrmap != NULL) + { + pst = addrmap_find (objfile->psymtabs_addrmap, pc); +@@ -343,6 +347,7 @@ find_pc_sect_psymtab (struct objfile *ob + } + + next: ++#endif + + /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs + which still have no corresponding full SYMTABs read. But it is not +@@ -361,7 +366,12 @@ find_pc_sect_psymtab (struct objfile *ob + + best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst, + msymbol); ++#ifdef CRASH_MERGE ++ if ((best_pst != NULL) && ++ gdb_line_number_callback(pc, pst->textlow, pst->texthigh)) ++#else + if (best_pst != NULL) ++#endif + return best_pst; + } + +--- gdb-7.6/gdb/symtab.c.orig ++++ gdb-7.6/gdb/symtab.c +@@ -1198,7 +1198,9 @@ demangle_for_lookup (const char *name, e + doesn't affect these calls since they are looking for a known + variable and thus can probably assume it will never hit the C++ + code). */ +- ++#ifdef CRASH_MERGE ++static void gdb_bait_and_switch(char *, struct symbol *); ++#endif + struct symbol * + lookup_symbol_in_language (const char *name, const struct block *block, + const domain_enum domain, enum language lang, +@@ -1212,17 +1214,30 @@ lookup_symbol_in_language (const char *n + is_a_field_of_this); + do_cleanups (cleanup); + ++#ifdef CRASH_MERGE ++ if (returnval && (domain == VAR_DOMAIN)) ++ gdb_bait_and_switch((char *)modified_name, returnval); ++#endif ++ + return returnval; + } + + /* Behave like lookup_symbol_in_language, but performed with the + current language. */ + ++#ifdef CRASH_MERGE ++static struct block *gdb_get_crash_block(void); ++#endif ++ + struct symbol * + lookup_symbol (const char *name, const struct block *block, + domain_enum domain, + struct field_of_this_result *is_a_field_of_this) + { ++#ifdef CRASH_MERGE ++ if (!block) ++ block = gdb_get_crash_block(); ++#endif + return lookup_symbol_in_language (name, block, domain, + current_language->la_language, + is_a_field_of_this); +@@ -5100,3 +5115,662 @@ When enabled, debugging messages are pri + + observer_attach_executable_changed (symtab_observer_executable_changed); + } ++ ++#ifdef CRASH_MERGE ++#include "gdb-stabs.h" ++#include "version.h" ++#define GDB_COMMON ++#include "../../defs.h" ++ ++static void get_member_data(struct gnu_request *, struct type *); ++static void dump_enum(struct type *, struct gnu_request *); ++static void eval_enum(struct type *, struct gnu_request *); ++static void gdb_get_line_number(struct gnu_request *); ++static void gdb_get_datatype(struct gnu_request *); ++static void gdb_get_symbol_type(struct gnu_request *); ++static void gdb_command_exists(struct gnu_request *); ++static void gdb_debug_command(struct gnu_request *); ++static void gdb_function_numargs(struct gnu_request *); ++static void gdb_add_symbol_file(struct gnu_request *); ++static void gdb_delete_symbol_file(struct gnu_request *); ++static void gdb_patch_symbol_values(struct gnu_request *); ++extern void replace_ui_file_FILE(struct ui_file *, FILE *); ++static void get_user_print_option_address(struct gnu_request *); ++extern int get_frame_offset(CORE_ADDR); ++static void gdb_set_crash_block(struct gnu_request *); ++void gdb_command_funnel(struct gnu_request *); ++ ++struct objfile *gdb_kernel_objfile = { 0 }; ++ ++static ulong gdb_merge_flags = 0; ++#define KERNEL_SYMBOLS_PATCHED (0x1) ++ ++#undef STREQ ++#define STREQ(A, B) (A && B && (strcmp(A, B) == 0)) ++ ++/* ++ * All commands from above come through here. ++ */ ++void ++gdb_command_funnel(struct gnu_request *req) ++{ ++ struct symbol *sym; ++ ++ if (req->command != GNU_VERSION) { ++ replace_ui_file_FILE(gdb_stdout, req->fp); ++ replace_ui_file_FILE(gdb_stderr, req->fp); ++ do_cleanups(all_cleanups()); ++ } ++ ++ switch (req->command) ++ { ++ case GNU_VERSION: ++ req->buf = (char *)version; ++ break; ++ ++ case GNU_PASS_THROUGH: ++ execute_command(req->buf, ++ req->flags & GNU_FROM_TTY_OFF ? FALSE : TRUE); ++ break; ++ ++ case GNU_USER_PRINT_OPTION: ++ get_user_print_option_address(req); ++ break; ++ ++ case GNU_RESOLVE_TEXT_ADDR: ++ sym = find_pc_function(req->addr); ++ if (!sym || TYPE_CODE(sym->type) != TYPE_CODE_FUNC) ++ req->flags |= GNU_COMMAND_FAILED; ++ break; ++ ++ case GNU_DISASSEMBLE: ++ if (req->addr2) ++ sprintf(req->buf, "disassemble 0x%lx 0x%lx", ++ req->addr, req->addr2); ++ else ++ sprintf(req->buf, "disassemble 0x%lx", req->addr); ++ execute_command(req->buf, TRUE); ++ break; ++ ++ case GNU_ADD_SYMBOL_FILE: ++ gdb_add_symbol_file(req); ++ break; ++ ++ case GNU_DELETE_SYMBOL_FILE: ++ gdb_delete_symbol_file(req); ++ break; ++ ++ case GNU_GET_LINE_NUMBER: ++ gdb_get_line_number(req); ++ break; ++ ++ case GNU_GET_DATATYPE: ++ gdb_get_datatype(req); ++ break; ++ ++ case GNU_GET_SYMBOL_TYPE: ++ gdb_get_symbol_type(req); ++ break; ++ ++ case GNU_COMMAND_EXISTS: ++ gdb_command_exists(req); ++ break; ++ ++ case GNU_ALPHA_FRAME_OFFSET: ++ req->value = 0; ++ break; ++ ++ case GNU_FUNCTION_NUMARGS: ++ gdb_function_numargs(req); ++ break; ++ ++ case GNU_DEBUG_COMMAND: ++ gdb_debug_command(req); ++ break; ++ ++ case GNU_PATCH_SYMBOL_VALUES: ++ gdb_patch_symbol_values(req); ++ break; ++ ++ case GNU_SET_CRASH_BLOCK: ++ gdb_set_crash_block(req); ++ break; ++ ++ default: ++ req->flags |= GNU_COMMAND_FAILED; ++ break; ++ } ++} ++ ++/* ++ * Given a PC value, return the file and line number. ++ */ ++static void ++gdb_get_line_number(struct gnu_request *req) ++{ ++ struct symtab_and_line sal; ++ struct symbol *sym; ++ CORE_ADDR pc; ++ ++#define LASTCHAR(s) (s[strlen(s)-1]) ++ ++ /* ++ * Prime the addrmap pump. ++ */ ++ if (req->name) ++ sym = lookup_symbol(req->name, 0, VAR_DOMAIN, 0); ++ ++ pc = req->addr; ++ ++ sal = find_pc_line(pc, 0); ++ ++ if (!sal.symtab) { ++ req->buf[0] = '\0'; ++ return; ++ } ++ ++ if (sal.symtab->filename && sal.symtab->dirname) { ++ if (sal.symtab->filename[0] == '/') ++ sprintf(req->buf, "%s: %d", ++ sal.symtab->filename, sal.line); ++ else ++ sprintf(req->buf, "%s%s%s: %d", ++ sal.symtab->dirname, ++ LASTCHAR(sal.symtab->dirname) == '/' ? "" : "/", ++ sal.symtab->filename, sal.line); ++ } ++} ++ ++ ++/* ++ * General purpose routine for determining datatypes. ++ */ ++ ++static void ++gdb_get_datatype(struct gnu_request *req) ++{ ++ register struct cleanup *old_chain = NULL; ++ register struct type *type; ++ register struct type *typedef_type; ++ struct expression *expr; ++ struct symbol *sym; ++ register int i; ++ struct field *nextfield; ++ struct value *val; ++ ++ if (gdb_CRASHDEBUG(2)) ++ console("gdb_get_datatype [%s] (a)\n", req->name); ++ ++ req->typecode = TYPE_CODE_UNDEF; ++ ++ /* ++ * lookup_symbol() will pick up struct and union names. ++ */ ++ sym = lookup_symbol(req->name, 0, STRUCT_DOMAIN, 0); ++ if (sym) { ++ req->typecode = TYPE_CODE(sym->type); ++ req->length = TYPE_LENGTH(sym->type); ++ if (req->member) ++ get_member_data(req, sym->type); ++ ++ if (TYPE_CODE(sym->type) == TYPE_CODE_ENUM) { ++ if (req->flags & GNU_PRINT_ENUMERATORS) ++ dump_enum(sym->type, req); ++ } ++ ++ return; ++ } ++ ++ /* ++ * Otherwise parse the expression. ++ */ ++ if (gdb_CRASHDEBUG(2)) ++ console("gdb_get_datatype [%s] (b)\n", req->name); ++ ++ expr = parse_expression(req->name); ++ ++ old_chain = make_cleanup(free_current_contents, &expr); ++ ++ ++ switch (expr->elts[0].opcode) ++ { ++ case OP_VAR_VALUE: ++ if (gdb_CRASHDEBUG(2)) ++ console("expr->elts[0].opcode: OP_VAR_VALUE\n"); ++ type = expr->elts[2].symbol->type; ++ if (req->flags & GNU_VAR_LENGTH_TYPECODE) { ++ req->typecode = TYPE_CODE(type); ++ req->length = TYPE_LENGTH(type); ++ } ++ if (TYPE_CODE(type) == TYPE_CODE_ENUM) { ++ req->typecode = TYPE_CODE(type); ++ req->value = SYMBOL_VALUE(expr->elts[2].symbol); ++ req->tagname = (char *)TYPE_TAG_NAME(type); ++ if (!req->tagname) { ++ val = evaluate_type(expr); ++ eval_enum(value_type(val), req); ++ } ++ } ++ break; ++ ++ case OP_TYPE: ++ if (gdb_CRASHDEBUG(2)) ++ console("expr->elts[0].opcode: OP_TYPE\n"); ++ type = expr->elts[1].type; ++ ++ req->typecode = TYPE_CODE(type); ++ req->length = TYPE_LENGTH(type); ++ ++ if (TYPE_CODE(type) == TYPE_CODE_TYPEDEF) { ++ req->is_typedef = TYPE_CODE_TYPEDEF; ++ if ((typedef_type = check_typedef(type))) { ++ req->typecode = TYPE_CODE(typedef_type); ++ req->length = TYPE_LENGTH(typedef_type); ++ type = typedef_type; ++ } ++ } ++ ++ if (TYPE_CODE(type) == TYPE_CODE_ENUM) { ++ if (req->is_typedef) ++ if (req->flags & GNU_PRINT_ENUMERATORS) { ++ if (req->is_typedef) ++ fprintf_filtered(gdb_stdout, ++ "typedef "); ++ dump_enum(type, req); ++ } ++ } ++ ++ if (req->member) ++ get_member_data(req, type); ++ ++ break; ++ ++ default: ++ if (gdb_CRASHDEBUG(2)) ++ console("expr->elts[0].opcode: %d (?)\n", ++ expr->elts[0].opcode); ++ break; ++ ++ } ++ ++ do_cleanups(old_chain); ++} ++ ++/* ++ * More robust enum list dump that gdb's, showing the value of each ++ * identifier, each on its own line. ++ */ ++static void ++dump_enum(struct type *type, struct gnu_request *req) ++{ ++ register int i; ++ int len; ++ int lastval; ++ ++ len = TYPE_NFIELDS (type); ++ lastval = 0; ++ if (TYPE_TAG_NAME(type)) ++ fprintf_filtered(gdb_stdout, ++ "enum %s {\n", TYPE_TAG_NAME (type)); ++ else ++ fprintf_filtered(gdb_stdout, "enum {\n"); ++ ++ for (i = 0; i < len; i++) { ++ fprintf_filtered(gdb_stdout, " %s", ++ TYPE_FIELD_NAME (type, i)); ++ if (lastval != TYPE_FIELD_BITPOS (type, i)) { ++ fprintf_filtered (gdb_stdout, " = %d", ++ TYPE_FIELD_BITPOS (type, i)); ++ lastval = TYPE_FIELD_BITPOS (type, i); ++ } else ++ fprintf_filtered(gdb_stdout, " = %d", lastval); ++ fprintf_filtered(gdb_stdout, "\n"); ++ lastval++; ++ } ++ if (TYPE_TAG_NAME(type)) ++ fprintf_filtered(gdb_stdout, "};\n"); ++ else ++ fprintf_filtered(gdb_stdout, "} %s;\n", req->name); ++} ++ ++/* ++ * Given an enum type with no tagname, determine its value. ++ */ ++static void ++eval_enum(struct type *type, struct gnu_request *req) ++{ ++ register int i; ++ int len; ++ int lastval; ++ ++ len = TYPE_NFIELDS (type); ++ lastval = 0; ++ ++ for (i = 0; i < len; i++) { ++ if (lastval != TYPE_FIELD_BITPOS (type, i)) { ++ lastval = TYPE_FIELD_BITPOS (type, i); ++ } ++ if (STREQ(TYPE_FIELD_NAME(type, i), req->name)) { ++ req->tagname = "(unknown)"; ++ req->value = lastval; ++ return; ++ } ++ lastval++; ++ } ++} ++ ++/* ++ * Walk through a struct type's list of fields looking for the desired ++ * member field, and when found, return its relevant data. ++ */ ++static void ++get_member_data(struct gnu_request *req, struct type *type) ++{ ++ register short i; ++ struct field *nextfield; ++ short nfields; ++ struct type *typedef_type; ++ ++ req->member_offset = -1; ++ ++ nfields = TYPE_MAIN_TYPE(type)->nfields; ++ nextfield = TYPE_MAIN_TYPE(type)->flds_bnds.fields; ++ ++ if (nfields == 0) { ++ struct type *newtype; ++ newtype = lookup_transparent_type(req->name); ++ if (newtype) { ++ console("get_member_data(%s.%s): switching type from %lx to %lx\n", ++ req->name, req->member, type, newtype); ++ nfields = TYPE_MAIN_TYPE(newtype)->nfields; ++ nextfield = TYPE_MAIN_TYPE(newtype)->flds_bnds.fields; ++ } ++ } ++ ++ for (i = 0; i < nfields; i++) { ++ if (STREQ(req->member, nextfield->name)) { ++ req->member_offset = nextfield->loc.bitpos; ++ req->member_length = TYPE_LENGTH(nextfield->type); ++ req->member_typecode = TYPE_CODE(nextfield->type); ++ if ((req->member_typecode == TYPE_CODE_TYPEDEF) && ++ (typedef_type = check_typedef(nextfield->type))) ++ req->member_length = TYPE_LENGTH(typedef_type); ++ return; ++ } ++ nextfield++; ++ } ++} ++ ++/* ++ * Check whether a command exists. If it doesn't, the command will be ++ * returned indirectly via the error_hook. ++ */ ++static void ++gdb_command_exists(struct gnu_request *req) ++{ ++ extern struct cmd_list_element *cmdlist; ++ register struct cmd_list_element *c; ++ ++ req->value = FALSE; ++ c = lookup_cmd(&req->name, cmdlist, "", 0, 1); ++ req->value = TRUE; ++} ++ ++static void ++gdb_function_numargs(struct gnu_request *req) ++{ ++ struct symbol *sym; ++ ++ sym = find_pc_function(req->pc); ++ ++ if (!sym || TYPE_CODE(sym->type) != TYPE_CODE_FUNC) { ++ req->flags |= GNU_COMMAND_FAILED; ++ return; ++ } ++ ++ req->value = (ulong)TYPE_NFIELDS(sym->type); ++} ++ ++struct load_module *gdb_current_load_module = NULL; ++ ++static void ++gdb_add_symbol_file(struct gnu_request *req) ++{ ++ register struct objfile *loaded_objfile = NULL; ++ register struct objfile *objfile; ++ register struct minimal_symbol *m; ++ struct load_module *lm; ++ int external, subsequent, found; ++ off_t offset; ++ ulong value, adjusted; ++ struct symbol *sym; ++ struct expression *expr; ++ struct cleanup *old_chain; ++ int i; ++ int allsect = 0; ++ char *secname; ++ char buf[80]; ++ ++ gdb_current_load_module = lm = (struct load_module *)req->addr; ++ ++ req->name = lm->mod_namelist; ++ gdb_delete_symbol_file(req); ++ ++ if ((lm->mod_flags & MOD_NOPATCH) == 0) { ++ for (i = 0 ; i < lm->mod_sections; i++) { ++ if (STREQ(lm->mod_section_data[i].name, ".text") && ++ (lm->mod_section_data[i].flags & SEC_FOUND)) ++ allsect = 1; ++ } ++ ++ if (!allsect) { ++ sprintf(req->buf, "add-symbol-file %s 0x%lx %s", lm->mod_namelist, ++ lm->mod_text_start ? lm->mod_text_start : lm->mod_base, ++ lm->mod_flags & MOD_DO_READNOW ? "-readnow" : ""); ++ if (lm->mod_data_start) { ++ sprintf(buf, " -s .data 0x%lx", lm->mod_data_start); ++ strcat(req->buf, buf); ++ } ++ if (lm->mod_bss_start) { ++ sprintf(buf, " -s .bss 0x%lx", lm->mod_bss_start); ++ strcat(req->buf, buf); ++ } ++ if (lm->mod_rodata_start) { ++ sprintf(buf, " -s .rodata 0x%lx", lm->mod_rodata_start); ++ strcat(req->buf, buf); ++ } ++ } else { ++ sprintf(req->buf, "add-symbol-file %s 0x%lx %s", lm->mod_namelist, ++ lm->mod_text_start, lm->mod_flags & MOD_DO_READNOW ? ++ "-readnow" : ""); ++ for (i = 0; i < lm->mod_sections; i++) { ++ secname = lm->mod_section_data[i].name; ++ if ((lm->mod_section_data[i].flags & SEC_FOUND) && ++ !STREQ(secname, ".text")) { ++ sprintf(buf, " -s %s 0x%lx", secname, ++ lm->mod_section_data[i].offset + lm->mod_base); ++ strcat(req->buf, buf); ++ } ++ } ++ } ++ } ++ ++ if (gdb_CRASHDEBUG(1)) ++ fprintf_filtered(gdb_stdout, "%s\n", req->buf); ++ ++ execute_command(req->buf, FALSE); ++ ++ ALL_OBJFILES(objfile) { ++ if (same_file(objfile->name, lm->mod_namelist)) { ++ loaded_objfile = objfile; ++ break; ++ } ++ } ++ ++ if (!loaded_objfile) ++ req->flags |= GNU_COMMAND_FAILED; ++} ++ ++static void ++gdb_delete_symbol_file(struct gnu_request *req) ++{ ++ register struct objfile *objfile; ++ ++ ALL_OBJFILES(objfile) { ++ if (STREQ(objfile->name, req->name) || ++ same_file(objfile->name, req->name)) { ++ free_objfile(objfile); ++ break; ++ } ++ } ++ ++ if (gdb_CRASHDEBUG(2)) { ++ fprintf_filtered(gdb_stdout, "current object files:\n"); ++ ALL_OBJFILES(objfile) ++ fprintf_filtered(gdb_stdout, " %s\n", objfile->name); ++ } ++} ++ ++/* ++ * Walk through all minimal_symbols, patching their values with the ++ * correct addresses. ++ */ ++static void ++gdb_patch_symbol_values(struct gnu_request *req) ++{ ++ struct minimal_symbol *msymbol; ++ struct objfile *objfile; ++ ++ req->name = PATCH_KERNEL_SYMBOLS_START; ++ patch_kernel_symbol(req); ++ ++ ALL_MSYMBOLS (objfile, msymbol) ++ { ++ req->name = (char *)msymbol->ginfo.name; ++ req->addr = (ulong)(&SYMBOL_VALUE_ADDRESS(msymbol)); ++ if (!patch_kernel_symbol(req)) { ++ req->flags |= GNU_COMMAND_FAILED; ++ break; ++ } ++ } ++ ++ req->name = PATCH_KERNEL_SYMBOLS_STOP; ++ patch_kernel_symbol(req); ++ ++ clear_symtab_users(0); ++ gdb_merge_flags |= KERNEL_SYMBOLS_PATCHED; ++} ++ ++static void ++gdb_get_symbol_type(struct gnu_request *req) ++{ ++ struct expression *expr; ++ struct value *val; ++ struct cleanup *old_chain = NULL; ++ struct type *type; ++ struct type *target_type; ++ ++ req->typecode = TYPE_CODE_UNDEF; ++ ++ expr = parse_expression (req->name); ++ old_chain = make_cleanup (free_current_contents, &expr); ++ val = evaluate_type (expr); ++ ++ type = value_type(val); ++ ++ req->type_name = (char *)TYPE_MAIN_TYPE(type)->name; ++ req->typecode = TYPE_MAIN_TYPE(type)->code; ++ req->length = type->length; ++ target_type = TYPE_MAIN_TYPE(type)->target_type; ++ ++ if (target_type) { ++ req->target_typename = (char *)TYPE_MAIN_TYPE(target_type)->name; ++ req->target_typecode = TYPE_MAIN_TYPE(target_type)->code; ++ req->target_length = target_type->length; ++ } ++ ++ if (req->member) ++ get_member_data(req, type); ++ ++ do_cleanups (old_chain); ++} ++ ++static void ++gdb_debug_command(struct gnu_request *req) ++{ ++ ++} ++ ++/* ++ * Only necessary on "patched" kernel symbol sessions, and called only by ++ * lookup_symbol(), pull a symbol value bait-and-switch operation by altering ++ * either a data symbol's address value or a text symbol's block start address. ++ */ ++static void ++gdb_bait_and_switch(char *name, struct symbol *sym) ++{ ++ struct minimal_symbol *msym; ++ struct block *block; ++ ++ if ((gdb_merge_flags & KERNEL_SYMBOLS_PATCHED) && ++ (msym = lookup_minimal_symbol(name, NULL, gdb_kernel_objfile))) { ++ if (sym->aclass == LOC_BLOCK) { ++ block = (struct block *)SYMBOL_BLOCK_VALUE(sym); ++ BLOCK_START(block) = SYMBOL_VALUE_ADDRESS(msym); ++ } else ++ SYMBOL_VALUE_ADDRESS(sym) = SYMBOL_VALUE_ADDRESS(msym); ++ } ++} ++ ++#include "valprint.h" ++ ++void ++get_user_print_option_address(struct gnu_request *req) ++{ ++ extern struct value_print_options user_print_options; ++ ++ req->addr = 0; ++ ++ if (strcmp(req->name, "output_format") == 0) ++ req->addr = (ulong)&user_print_options.output_format; ++ if (strcmp(req->name, "print_max") == 0) ++ req->addr = (ulong)&user_print_options.print_max; ++ if (strcmp(req->name, "prettyprint_structs") == 0) ++ req->addr = (ulong)&user_print_options.prettyprint_structs; ++ if (strcmp(req->name, "prettyprint_arrays") == 0) ++ req->addr = (ulong)&user_print_options.prettyprint_arrays; ++ if (strcmp(req->name, "repeat_count_threshold") == 0) ++ req->addr = (ulong)&user_print_options.repeat_count_threshold; ++ if (strcmp(req->name, "stop_print_at_null") == 0) ++ req->addr = (ulong)&user_print_options.stop_print_at_null; ++ if (strcmp(req->name, "output_radix") == 0) ++ req->addr = (ulong)&output_radix; ++} ++ ++CORE_ADDR crash_text_scope; ++ ++static void ++gdb_set_crash_block(struct gnu_request *req) ++{ ++ if (!req->addr) { /* debug */ ++ crash_text_scope = 0; ++ return; ++ } ++ ++ if ((req->addr2 = (ulong)block_for_pc(req->addr))) ++ crash_text_scope = req->addr; ++ else { ++ crash_text_scope = 0; ++ req->flags |= GNU_COMMAND_FAILED; ++ } ++} ++ ++static struct block * ++gdb_get_crash_block(void) ++{ ++ if (crash_text_scope) ++ return block_for_pc(crash_text_scope); ++ else ++ return NULL; ++} ++#endif +--- gdb-7.6/gdb/c-typeprint.c.orig ++++ gdb-7.6/gdb/c-typeprint.c +@@ -1097,7 +1097,8 @@ c_type_print_base (struct type *type, st + fprintf_filtered (stream, "static "); + c_print_type (TYPE_FIELD_TYPE (type, i), + TYPE_FIELD_NAME (type, i), +- stream, show - 1, level + 4, ++ stream, strlen(TYPE_FIELD_NAME (type, i)) ? ++ show - 1 : show, level + 4, + &local_flags); + if (!field_is_static (&TYPE_FIELD (type, i)) + && TYPE_FIELD_PACKED (type, i)) +--- gdb-7.6/gdb/xml-syscall.c.orig ++++ gdb-7.6/gdb/xml-syscall.c +@@ -38,7 +38,11 @@ + static void + syscall_warn_user (void) + { ++#ifdef CRASH_MERGE ++ static int have_warned = 1; ++#else + static int have_warned = 0; ++#endif + if (!have_warned) + { + have_warned = 1; +--- gdb-7.6/gdb/exceptions.c.orig ++++ gdb-7.6/gdb/exceptions.c +@@ -218,6 +218,10 @@ exceptions_state_mc_action_iter_1 (void) + + /* Return EXCEPTION to the nearest containing catch_errors(). */ + ++#ifdef CRASH_MERGE ++void (*error_hook) (void) ATTRIBUTE_NORETURN; ++#endif ++ + void + throw_exception (struct gdb_exception exception) + { +@@ -225,6 +229,13 @@ throw_exception (struct gdb_exception ex + immediate_quit = 0; + + do_cleanups (all_cleanups ()); ++#ifdef CRASH_MERGE ++ if (error_hook) { ++ fprintf_filtered(gdb_stderr, "%s\n", exception.message); ++ (*error_hook)(); ++ } else ++ fprintf_filtered(gdb_stderr, "gdb called without error_hook: %s\n", exception.message); ++#endif + + /* Jump to the containing catch_errors() call, communicating REASON + to that call via setjmp's return value. Note that REASON can't +--- gdb-7.6/gdb/valprint.h.orig ++++ gdb-7.6/gdb/valprint.h +@@ -152,11 +152,17 @@ extern void print_function_pointer_addre + struct gdbarch *gdbarch, + CORE_ADDR address, + struct ui_file *stream); +- ++#ifdef CRASH_MERGE ++extern int valprint_read_string (CORE_ADDR addr, int len, int width, ++ unsigned int fetchlimit, ++ enum bfd_endian byte_order, gdb_byte **buffer, ++ int *bytes_read); ++#else + extern int read_string (CORE_ADDR addr, int len, int width, + unsigned int fetchlimit, + enum bfd_endian byte_order, gdb_byte **buffer, + int *bytes_read); ++#endif + + extern void val_print_optimized_out (struct ui_file *stream); + +--- gdb-7.6/gdb/target.c.orig ++++ gdb-7.6/gdb/target.c +@@ -1779,6 +1779,13 @@ target_xfer_partial (struct target_ops * + int + target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len) + { ++#ifdef CRASH_MERGE ++ extern int gdb_readmem_callback(unsigned long, void *, int, int); ++ if (gdb_readmem_callback(memaddr, (void *)myaddr, len, 0)) ++ return 0; ++ else ++ return EIO; ++#endif + /* Dispatch to the topmost target, not the flattened current_target. + Memory accesses check target->to_has_(all_)memory, and the + flattened target doesn't inherit those. */ +@@ -1814,6 +1821,13 @@ target_read_stack (CORE_ADDR memaddr, gd + int + target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len) + { ++#ifdef CRASH_MERGE ++ extern int gdb_readmem_callback(unsigned long, void *, int, int); ++ if (gdb_readmem_callback(memaddr, (void *)myaddr, len, 1)) ++ return 0; ++ else ++ return EIO; ++#endif + /* Dispatch to the topmost target, not the flattened current_target. + Memory accesses check target->to_has_(all_)memory, and the + flattened target doesn't inherit those. */ +--- gdb-7.6/gdb/printcmd.c.orig ++++ gdb-7.6/gdb/printcmd.c +@@ -1001,11 +1001,62 @@ print_command_1 (char *exp, int voidprin + } + + static void ++print_command_2 (char *exp, int inspect, int voidprint) ++{ ++ struct expression *expr; ++ struct cleanup *old_chain = 0; ++ char format = 0; ++ struct value *val; ++ struct format_data fmt; ++ int cleanup = 0; ++ ++ if (exp && *exp == '/') ++ { ++ exp++; ++ fmt = decode_format (&exp, last_format, 0); ++ validate_format (fmt, "print"); ++ last_format = format = fmt.format; ++ } ++ else ++ { ++ fmt.count = 1; ++ fmt.format = 0; ++ fmt.size = 0; ++ fmt.raw = 0; ++ } ++ ++ if (exp && *exp) ++ { ++ expr = parse_expression (exp); ++ old_chain = make_cleanup (free_current_contents, &expr); ++ cleanup = 1; ++ val = evaluate_expression (expr); ++ } ++ else ++ val = access_value_history (0); ++ ++ printf_filtered ("%d %d %d %d %d %d\n", ++ TYPE_CODE (check_typedef(value_type (val))), ++ TYPE_UNSIGNED (check_typedef(value_type (val))), ++ TYPE_LENGTH (check_typedef(value_type(val))), ++ value_offset (val), value_bitpos (val), value_bitsize(val)); ++ ++ if (cleanup) ++ do_cleanups (old_chain); ++} ++ ++static void + print_command (char *exp, int from_tty) + { + print_command_1 (exp, 1); + } + ++static void ++printm_command (char *exp, int from_tty) ++{ ++ print_command_2 (exp, 0, 1); ++} ++ + /* Same as print, except it doesn't print void results. */ + static void + call_command (char *exp, int from_tty) +@@ -2593,6 +2644,12 @@ EXP may be preceded with /FMT, where FMT + but no count or size letter (see \"x\" command).")); + set_cmd_completer (c, expression_completer); + add_com_alias ("p", "print", class_vars, 1); ++ ++ c = add_com ("printm", class_vars, printm_command, _("\ ++Similar to \"print\" command, but it used to print the type, size, offset,\n\ ++bitpos and bitsize of the expression EXP.")); ++ set_cmd_completer (c, expression_completer); ++ + add_com_alias ("inspect", "print", class_vars, 1); + + add_setshow_uinteger_cmd ("max-symbolic-offset", no_class, +--- gdb-7.6/gdb/ui-file.c.orig ++++ gdb-7.6/gdb/ui-file.c +@@ -671,6 +671,17 @@ gdb_fopen (char *name, char *mode) + return stdio_file_new (f, 1); + } + ++#ifdef CRASH_MERGE ++void ++replace_ui_file_FILE(struct ui_file *file, FILE *fp) ++{ ++ struct stdio_file *stdio_file; ++ ++ stdio_file = (struct stdio_file *)ui_file_data(file); ++ stdio_file->file = fp; ++} ++#endif ++ + /* ``struct ui_file'' implementation that maps onto two ui-file objects. */ + + static ui_file_write_ftype tee_file_write; +--- gdb-7.6/gdb/main.c.orig ++++ gdb-7.6/gdb/main.c +@@ -806,7 +806,7 @@ captured_main (void *data) + { + print_gdb_version (gdb_stdout); + wrap_here (""); +- printf_filtered ("\n"); ++ printf_filtered ("\n\n"); + exit (0); + } + +@@ -853,6 +853,13 @@ captured_main (void *data) + } + } + ++#ifdef CRASH_MERGE ++{ ++ extern void update_gdb_hooks(void); ++ update_gdb_hooks(); ++} ++#endif ++ + /* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets + GDB retain the old MI1 interpreter startup behavior. Output the + copyright message after the interpreter is installed when it is +@@ -880,7 +887,11 @@ captured_main (void *data) + processed; it sets global parameters, which are independent of + what file you are debugging or what directory you are in. */ + if (system_gdbinit && !inhibit_gdbinit) ++#ifdef CRASH_MERGE ++ catch_command_errors (source_script, system_gdbinit, -1, RETURN_MASK_ALL); ++#else + catch_command_errors (source_script, system_gdbinit, 0, RETURN_MASK_ALL); ++#endif + + /* Read and execute $HOME/.gdbinit file, if it exists. This is done + *before* all the command line arguments are processed; it sets +@@ -888,7 +899,11 @@ captured_main (void *data) + debugging or what directory you are in. */ + + if (home_gdbinit && !inhibit_gdbinit && !inhibit_home_gdbinit) ++#ifdef CRASH_MERGE ++ catch_command_errors (source_script, home_gdbinit, -1, RETURN_MASK_ALL); ++#else + catch_command_errors (source_script, home_gdbinit, 0, RETURN_MASK_ALL); ++#endif + + /* Process '-ix' and '-iex' options early. */ + for (i = 0; VEC_iterate (cmdarg_s, cmdarg_vec, i, cmdarg_p); i++) +@@ -929,8 +944,12 @@ captured_main (void *data) + catch_command_errors returns non-zero on success! */ + if (catch_command_errors (exec_file_attach, execarg, + !batch_flag, RETURN_MASK_ALL)) ++#ifdef CRASH_MERGE ++ catch_command_errors (symbol_file_add_main, symarg, 0, RETURN_MASK_ALL); ++#else + catch_command_errors (symbol_file_add_main, symarg, + !batch_flag, RETURN_MASK_ALL); ++#endif + } + else + { +@@ -992,8 +1011,12 @@ captured_main (void *data) + { + auto_load_local_gdbinit_loaded = 1; + ++#ifdef CRASH_MERGE ++ catch_command_errors (source_script, local_gdbinit, -1, RETURN_MASK_ALL); ++#else + catch_command_errors (source_script, local_gdbinit, 0, + RETURN_MASK_ALL); ++#endif + } + } + +@@ -1039,6 +1062,12 @@ captured_main (void *data) + while (1) + { + catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL); ++#ifdef CRASH_MERGE ++ { ++ int console(char *, ...); ++ console("\n"); ++ } ++#endif + } + /* No exit -- exit is through quit_command. */ + } +@@ -1053,6 +1082,23 @@ gdb_main (struct captured_main_args *arg + return 1; + } + ++#ifdef CRASH_MERGE ++/* ++ * NOTE: adapted from gdb.c, which is no longer built in; changed name of ++ * original main() to gdb_main_entry() for use as crash entry point ++ */ ++int ++gdb_main_entry (int argc, char **argv) ++{ ++ struct captured_main_args args; ++ memset (&args, 0, sizeof args); ++ args.argc = argc; ++ args.argv = argv; ++ args.use_windows = 0; ++ args.interpreter_p = INTERP_CONSOLE; ++ return gdb_main (&args); ++} ++#endif + + /* Don't use *_filtered for printing help. We don't want to prompt + for continue no matter how small the screen or how much we're going +--- gdb-7.6/gdb/valprint.c.orig ++++ gdb-7.6/gdb/valprint.c +@@ -1768,8 +1768,13 @@ partial_memory_read (CORE_ADDR memaddr, + this function instead? */ + + int ++#ifdef CRASH_MERGE ++valprint_read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit, ++ enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read) ++#else + read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit, + enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read) ++#endif + { + int found_nul; /* Non-zero if we found the nul char. */ + int errcode; /* Errno returned from bad reads. */ +@@ -2472,8 +2477,13 @@ val_print_string (struct type *elttype, + fetchlimit = (len == -1 ? options->print_max : min (len, + options->print_max)); + ++#ifdef CRASH_MERGE ++ errcode = valprint_read_string (addr, len, width, fetchlimit, byte_order, ++ &buffer, &bytes_read); ++#else + errcode = read_string (addr, len, width, fetchlimit, byte_order, + &buffer, &bytes_read); ++#endif + old_chain = make_cleanup (xfree, buffer); + + addr += bytes_read; +--- gdb-7.6/gdb/Makefile.in.orig ++++ gdb-7.6/gdb/Makefile.in +@@ -422,7 +422,7 @@ CONFIG_UNINSTALL = @CONFIG_UNINSTALL@ + # It is also possible that you will need to add -I/usr/include/sys if + # your system doesn't have fcntl.h in /usr/include (which is where it + # should be according to Posix). +-DEFS = @DEFS@ ++DEFS = -DCRASH_MERGE @DEFS@ + GDB_CFLAGS = -I. -I$(srcdir) -I$(srcdir)/common -I$(srcdir)/config \ + -DLOCALEDIR="\"$(localedir)\"" $(DEFS) + +@@ -934,7 +934,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $ + + TSOBS = inflow.o + +-SUBDIRS = doc @subdirs@ data-directory $(GNULIB_BUILDDIR) ++SUBDIRS = build_no_subdirs + CLEANDIRS = $(SUBDIRS) + + # List of subdirectories in the build tree that must exist. +@@ -969,8 +969,8 @@ generated_files = config.h observer.h ob + $(COMPILE) $< + $(POSTCOMPILE) + +-all: gdb$(EXEEXT) $(CONFIG_ALL) +- @$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do ++all: gdb$(EXEEXT) ++ @$(MAKE) -s $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do + + installcheck: + +@@ -1172,15 +1172,16 @@ libgdb.a: $(LIBGDB_OBS) + + # Removing the old gdb first works better if it is running, at least on SunOS. + gdb$(EXEEXT): gdb.o $(LIBGDB_OBS) $(ADD_DEPS) $(CDEPS) $(TDEPLIBS) +- rm -f gdb$(EXEEXT) ++ @rm -f gdb$(EXEEXT) ++ @(cd ../..; make --no-print-directory GDB_FLAGS=-DGDB_7_6 library) + $(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \ +- -o gdb$(EXEEXT) gdb.o $(LIBGDB_OBS) \ +- $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) ++ -o $(shell /bin/cat mergeobj) $(LIBGDB_OBS) \ ++ $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) $(shell /bin/cat mergelibs) + + # Convenience rule to handle recursion. + $(LIBGNU) $(GNULIB_H): all-lib + all-lib: $(GNULIB_BUILDDIR)/Makefile +- @$(MAKE) $(FLAGS_TO_PASS) DO=all DODIRS=$(GNULIB_BUILDDIR) subdir_do ++ @$(MAKE) $(FLAGS_TO_PASS) DO=all DODIRS=$(GNULIB_BUILDDIR) subdir_do -s + .PHONY: all-lib + + # Convenience rule to handle recursion. +@@ -1389,12 +1390,12 @@ $(srcdir)/copying.c: @MAINTAINER_MODE_TR + mv $(srcdir)/copying.tmp $(srcdir)/copying.c + + version.c: Makefile version.in +- rm -f version.c-tmp version.c +- echo '#include "version.h"' >> version.c-tmp +- echo 'const char version[] = "'"`sed q ${srcdir}/version.in`"'";' >> version.c-tmp +- echo 'const char host_name[] = "$(host_alias)";' >> version.c-tmp +- echo 'const char target_name[] = "$(target_alias)";' >> version.c-tmp +- mv version.c-tmp version.c ++ @rm -f version.c-tmp version.c ++ @echo '#include "version.h"' >> version.c-tmp ++ @echo 'const char version[] = "'"`sed q ${srcdir}/version.in`"'";' >> version.c-tmp ++ @echo 'const char host_name[] = "$(host_alias)";' >> version.c-tmp ++ @echo 'const char target_name[] = "$(target_alias)";' >> version.c-tmp ++ @mv version.c-tmp version.c + + observer.h: observer.sh doc/observer.texi + ${srcdir}/observer.sh h ${srcdir}/doc/observer.texi observer.h +--- gdb-7.6/gdb/c-lang.c.orig ++++ gdb-7.6/gdb/c-lang.c +@@ -307,7 +307,11 @@ c_get_string (struct value *value, gdb_b + { + CORE_ADDR addr = value_as_address (value); + ++#ifdef CRASH_MERGE ++ err = valprint_read_string (addr, *length, width, fetchlimit, ++#else + err = read_string (addr, *length, width, fetchlimit, ++#endif + byte_order, buffer, length); + if (err) + { +--- gdb-7.6/readline/rltypedefs.h.orig ++++ gdb-7.6/readline/rltypedefs.h +@@ -31,10 +31,10 @@ extern "C" { + #if !defined (_FUNCTION_DEF) + # define _FUNCTION_DEF + +-typedef int Function (); +-typedef void VFunction (); +-typedef char *CPFunction (); +-typedef char **CPPFunction (); ++typedef int Function (void); ++typedef void VFunction (void); ++typedef char *CPFunction (void); ++typedef char **CPPFunction (void); + + #endif /* _FUNCTION_DEF */ + +--- gdb-7.6/readline/readline.h.orig ++++ gdb-7.6/readline/readline.h +@@ -378,7 +378,7 @@ extern int rl_crlf PARAMS((void)); + #if defined (USE_VARARGS) && defined (PREFER_STDARG) + extern int rl_message (const char *, ...) __attribute__((__format__ (printf, 1, 2))); + #else +-extern int rl_message (); ++extern int rl_message (void); + #endif + + extern int rl_show_char PARAMS((int)); +--- gdb-7.6/readline/misc.c.orig ++++ gdb-7.6/readline/misc.c +@@ -405,7 +405,7 @@ _rl_history_set_point () + + #if defined (VI_MODE) + if (rl_editing_mode == vi_mode && _rl_keymap != vi_insertion_keymap) +- rl_point = 0; ++ rl_point = rl_end; + #endif /* VI_MODE */ + + if (rl_editing_mode == emacs_mode) +--- gdb-7.6/Makefile.in.orig ++++ gdb-7.6/Makefile.in +@@ -342,6 +342,9 @@ AR_FOR_BUILD = @AR_FOR_BUILD@ + AS_FOR_BUILD = @AS_FOR_BUILD@ + CC_FOR_BUILD = @CC_FOR_BUILD@ + CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@ ++ifeq (${CRASH_TARGET}, PPC64) ++CFLAGS_FOR_BUILD += -m64 -fPIC ++endif + CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@ + CXX_FOR_BUILD = @CXX_FOR_BUILD@ + DLLTOOL_FOR_BUILD = @DLLTOOL_FOR_BUILD@ +@@ -407,6 +410,9 @@ GNATBIND = @GNATBIND@ + GNATMAKE = @GNATMAKE@ + + CFLAGS = @CFLAGS@ ++ifeq (${CRASH_TARGET}, PPC64) ++CFLAGS += -m64 -fPIC ++endif + LDFLAGS = @LDFLAGS@ + LIBCFLAGS = $(CFLAGS) + CXXFLAGS = @CXXFLAGS@ +--- gdb-7.6/gdb/defs.h.orig ++++ gdb-7.6/gdb/defs.h +@@ -802,4 +802,8 @@ enum block_enum + + #include "utils.h" + ++#ifdef CRASH_MERGE ++extern int gdb_main_entry(int, char **); ++extern void replace_ui_file_FILE(struct ui_file *, FILE *); ++#endif + #endif /* #ifndef DEFS_H */ +--- gdb-7.6/bfd/elflink.c.orig ++++ gdb-7.6/bfd/elflink.c +@@ -4730,7 +4730,7 @@ error_free_dyn: + struct elf_link_hash_entry *hlook; + asection *slook; + bfd_vma vlook; +- size_t i, j, idx; ++ size_t i, j, idx = 0; + + hlook = weaks; + weaks = hlook->u.weakdef; +--- gdb-7.6/gdb/s390-nat.c.orig ++++ gdb-7.6/gdb/s390-nat.c +@@ -37,6 +37,8 @@ + #include + #include + ++#include ++ + #ifndef HWCAP_S390_HIGH_GPRS + #define HWCAP_S390_HIGH_GPRS 512 + #endif +--- gdb-7.6/gdb/printcmd.c.orig ++++ gdb-7.6/gdb/printcmd.c +@@ -573,11 +573,21 @@ print_address_symbolic (struct gdbarch * + int unmapped = 0; + int offset = 0; + int line = 0; ++#ifdef CRASH_MERGE ++ extern int gdb_print_callback(unsigned long); ++#endif + + /* Throw away both name and filename. */ + struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); + make_cleanup (free_current_contents, &filename); + ++#ifdef CRASH_MERGE ++ if (!gdb_print_callback(addr)) { ++ do_cleanups (cleanup_chain); ++ return 0; ++ } ++#endif ++ + if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset, + &filename, &line, &unmapped)) + { diff --git a/gdb_interface.c b/gdb_interface.c new file mode 100644 index 00000000..af2855f9 --- /dev/null +++ b/gdb_interface.c @@ -0,0 +1,1027 @@ +/* gdb_interface.c - core analysis suite + * + * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2013 David Anderson + * Copyright (C) 2002-2013 Red Hat, Inc. 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. + */ + +#include "defs.h" + +static void exit_after_gdb_info(void); +static int is_restricted_command(char *, ulong); +static void strip_redirection(char *); +int get_frame_offset(ulong); + +int *gdb_output_format; +unsigned int *gdb_print_max; +int *gdb_prettyprint_structs; +int *gdb_prettyprint_arrays; +int *gdb_repeat_count_threshold; +int *gdb_stop_print_at_null; +unsigned int *gdb_output_radix; + +static ulong gdb_user_print_option_address(char *); + +/* + * Called from main() this routine sets up the call-back hook such that + * gdb's main() routine -- renamed gdb_main() -- will call back to + * our main_loop() after gdb initializes. + */ +void +gdb_main_loop(int argc, char **argv) +{ + argc = 1; + + if (pc->flags & SILENT) { + if (pc->flags & READNOW) + argv[argc++] = "--readnow"; + argv[argc++] = "--quiet"; + argv[argc++] = pc->namelist_debug ? + pc->namelist_debug : + (pc->debuginfo_file && (st->flags & CRC_MATCHES) ? + pc->debuginfo_file : pc->namelist); + } else { + if (pc->flags & READNOW) + argv[argc++] = "--readnow"; + argv[argc++] = pc->namelist_debug ? + pc->namelist_debug : + (pc->debuginfo_file && (st->flags & CRC_MATCHES) ? + pc->debuginfo_file : pc->namelist); + } + + if (CRASHDEBUG(1)) { + int i; + fprintf(fp, "gdb "); + for (i = 1; i < argc; i++) + fprintf(fp, "%s ", argv[i]); + fprintf(fp, "\n"); + } + + optind = 0; +#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) + command_loop_hook = main_loop; +#else + deprecated_command_loop_hook = main_loop; +#endif + gdb_main_entry(argc, argv); +} + +/* + * Update any hooks that gdb has set. + */ +void +update_gdb_hooks(void) +{ +#if defined(GDB_6_0) || defined(GDB_6_1) + command_loop_hook = pc->flags & VERSION_QUERY ? + exit_after_gdb_info : main_loop; + target_new_objfile_hook = NULL; +#endif +#if defined(GDB_7_0) || defined(GDB_7_3_1) || defined(GDB_7_6) + deprecated_command_loop_hook = pc->flags & VERSION_QUERY ? + exit_after_gdb_info : main_loop; +#endif +} + +void +gdb_readnow_warning(void) +{ + if ((THIS_GCC_VERSION >= GCC(3,4,0)) && (THIS_GCC_VERSION < GCC(4,0,0)) + && !(pc->flags & READNOW)) { + fprintf(stderr, + "WARNING: Because this kernel was compiled with gcc version %d.%d.%d, certain\n" + " commands or command options may fail unless crash is invoked with\n" + " the \"--readnow\" command line option.\n\n", + kt->gcc_version[0], + kt->gcc_version[1], + kt->gcc_version[2]); + } +} + +/* + * Used only by the -v command line option, get gdb to initialize itself + * with no arguments, print its version and GPL paragraph, and then call + * back to exit_after_gdb_info(). + */ +void +display_gdb_banner(void) +{ + optind = 0; +#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) + command_loop_hook = exit_after_gdb_info; +#else + deprecated_command_loop_hook = exit_after_gdb_info; +#endif + args[0] = "gdb"; + args[1] = "-version"; + gdb_main_entry(2, args); +} + +static void +exit_after_gdb_info(void) +{ + fprintf(fp, "\n"); + clean_exit(0); +} + +/* + * Stash a copy of the gdb version locally. This can be called before + * gdb gets initialized, so bypass gdb_interface(). + */ +void +get_gdb_version(void) +{ + struct gnu_request request; + + if (!pc->gdb_version) { + request.command = GNU_VERSION; + gdb_command_funnel(&request); /* bypass gdb_interface() */ + pc->gdb_version = request.buf; + } +} + +void +gdb_session_init(void) +{ + struct gnu_request *req; + int debug_data_pulled_in; + + if (!have_partial_symbols() && !have_full_symbols()) + no_debugging_data(FATAL); + + /* + * Restore the SIGINT and SIGPIPE handlers, which got temporarily + * re-assigned by gdb. The SIGINT call also initializes GDB's + * SIGINT sigaction. + */ + SIGACTION(SIGINT, restart, &pc->sigaction, &pc->gdb_sigaction); + SIGACTION(SIGPIPE, SIG_IGN, &pc->sigaction, NULL); + + if (!(pc->flags & DROP_CORE)) + SIGACTION(SIGSEGV, restart, &pc->sigaction, NULL); + + /* + * Set up pointers to gdb variables. + */ +#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) + gdb_output_format = &output_format; + gdb_print_max = &print_max; + gdb_prettyprint_structs = &prettyprint_structs; + gdb_prettyprint_arrays = &prettyprint_arrays; + gdb_repeat_count_threshold = &repeat_count_threshold; + gdb_stop_print_at_null = &stop_print_at_null; + gdb_output_radix = &output_radix; +#else + gdb_output_format = (int *) + gdb_user_print_option_address("output_format"); + gdb_print_max = (unsigned int *) + gdb_user_print_option_address("print_max"); + gdb_prettyprint_structs = (int *) + gdb_user_print_option_address("prettyprint_structs"); + gdb_prettyprint_arrays = (int *) + gdb_user_print_option_address("prettyprint_arrays"); + gdb_repeat_count_threshold = (int *) + gdb_user_print_option_address("repeat_count_threshold"); + gdb_stop_print_at_null = (int *) + gdb_user_print_option_address("stop_print_at_null"); + gdb_output_radix = (unsigned int *) + gdb_user_print_option_address("output_radix"); +#endif + /* + * If the output radix is set via the --hex or --dec command line + * option, then pc->output_radix will be non-zero; otherwise use + * the gdb default. + */ + if (pc->output_radix) { + *gdb_output_radix = pc->output_radix; + *gdb_output_format = (*gdb_output_radix == 10) ? 0 : 'x'; + } + + switch (*gdb_output_radix) + { + case 10: + case 16: + pc->output_radix = *gdb_output_radix; + break; + default: + pc->output_radix = *gdb_output_radix = 10; + *gdb_output_format = 0; + } + + *gdb_prettyprint_structs = 1; + *gdb_repeat_count_threshold = 0x7fffffff; + *gdb_print_max = 256; +#ifdef GDB_5_3 + gdb_disassemble_from_exec = 0; +#endif + + pc->flags |= GDB_INIT; /* set here so gdb_interface will work */ + + req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request)); + req->buf = GETBUF(BUFSIZE); + + /* + * Make sure the namelist has symbolic data. Later versions of + * gcc may require that debug data be pulled in by printing a + * static kernel data structure. + */ + debug_data_pulled_in = FALSE; +retry: + BZERO(req->buf, BUFSIZE); + req->command = GNU_GET_DATATYPE; + req->name = XEN_HYPER_MODE() ? "page_info" : "task_struct"; + req->flags = GNU_RETURN_ON_ERROR; + gdb_interface(req); + + if (req->flags & GNU_COMMAND_FAILED) { + if (XEN_HYPER_MODE()) + no_debugging_data(WARNING); /* just bail out */ + + if (!debug_data_pulled_in) { + if (CRASHDEBUG(1)) + error(INFO, + "gdb_session_init: pulling in debug data by accessing init_mm.mmap %s\n", + symbol_exists("sysfs_mount") ? + "and syfs_mount" : ""); + debug_data_pulled_in = TRUE; + req->command = GNU_PASS_THROUGH; + req->flags = GNU_RETURN_ON_ERROR|GNU_NO_READMEM; + req->name = NULL; + if (symbol_exists("sysfs_mount")) + sprintf(req->buf, "print sysfs_mount, init_mm.mmap"); + else + sprintf(req->buf, "print init_mm.mmap"); + gdb_interface(req); + if (!(req->flags & GNU_COMMAND_FAILED)) + goto retry; + } + no_debugging_data(WARNING); + } + + if (pc->flags & KERNEL_DEBUG_QUERY) { + fprintf(fp, "\n%s: %s: contains debugging data\n\n", + pc->program_name, pc->namelist); + if (REMOTE()) + remote_exit(); + clean_exit(0); + } + + /* + * Set up any pre-ordained gdb settings here that can't be + * accessed directly. + */ + + req->command = GNU_PASS_THROUGH; + req->name = NULL, req->flags = 0; + sprintf(req->buf, "set height 0"); + gdb_interface(req); + + req->command = GNU_PASS_THROUGH; + req->name = NULL, req->flags = 0; + sprintf(req->buf, "set width 0"); + gdb_interface(req); + + /* + * Patch gdb's symbol values with the correct values from either + * the System.map or non-debug vmlinux, whichever is in effect. + */ + if ((pc->flags & SYSMAP) || (kt->flags & (RELOC_SET|RELOC_FORCE)) || + (pc->namelist_debug && !pc->debuginfo_file)) { + req->command = GNU_PATCH_SYMBOL_VALUES; + req->flags = GNU_RETURN_ON_ERROR; + gdb_interface(req); + if (req->flags & GNU_COMMAND_FAILED) + error(FATAL, "patching of gdb symbol values failed\n"); + } else if (!(pc->flags & SILENT)) + fprintf(fp, "\n"); + + + FREEBUF(req->buf); + FREEBUF(req); +} + +/* + * Quickest way to gdb -- just pass a command string to pass through. + */ +int +gdb_pass_through(char *cmd, FILE *fptr, ulong flags) +{ + struct gnu_request *req; + int retval; + + if (CRASHDEBUG(1)) + console("gdb_pass_through: [%s]\n", cmd); + + req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request)); + req->buf = cmd; + if (fptr) + req->fp = fptr; + req->command = GNU_PASS_THROUGH; + req->flags = flags; + + gdb_interface(req); + + if ((req->flags & (GNU_RETURN_ON_ERROR|GNU_COMMAND_FAILED)) == + (GNU_RETURN_ON_ERROR|GNU_COMMAND_FAILED)) + retval = FALSE; + else + retval = TRUE; + + FREEBUF(req); + + return retval; +} + + +/* + * General purpose routine for passing commands to gdb. All gdb commands + * come through here, where they are passed to gdb_command_funnel(). + */ +void +gdb_interface(struct gnu_request *req) +{ + if (!(pc->flags & GDB_INIT)) + error(FATAL, "gdb_interface: gdb not initialized?\n"); + + if (output_closed()) + restart(0); + + if (!req->fp) { + req->fp = ((pc->flags & RUNTIME) || (pc->flags2 & ALLOW_FP)) ? + fp : CRASHDEBUG(1) ? fp : pc->nullfp; + } + + pc->cur_req = req; + pc->cur_gdb_cmd = req->command; + + if (req->flags & GNU_RETURN_ON_ERROR) { + error_hook = gdb_error_hook; + if (setjmp(pc->gdb_interface_env)) { + pc->last_gdb_cmd = pc->cur_gdb_cmd; + pc->cur_gdb_cmd = 0; + pc->cur_req = NULL; + req->flags |= GNU_COMMAND_FAILED; + pc->flags &= ~IN_GDB; + return; + } + } else + error_hook = NULL; + + if (CRASHDEBUG(2)) + dump_gnu_request(req, IN_GDB); + + if (!(pc->flags & DROP_CORE)) + SIGACTION(SIGSEGV, restart, &pc->sigaction, NULL); + else + SIGACTION(SIGSEGV, SIG_DFL, &pc->sigaction, NULL); + + if (interruptible()) { + SIGACTION(SIGINT, pc->gdb_sigaction.sa_handler, + &pc->gdb_sigaction, NULL); + } else { + SIGACTION(SIGINT, SIG_IGN, &pc->sigaction, NULL); + SIGACTION(SIGPIPE, SIG_IGN, &pc->sigaction, NULL); + } + + pc->flags |= IN_GDB; + gdb_command_funnel(req); + pc->flags &= ~IN_GDB; + + SIGACTION(SIGINT, restart, &pc->sigaction, NULL); + SIGACTION(SIGSEGV, SIG_DFL, &pc->sigaction, NULL); + + if (CRASHDEBUG(2)) + dump_gnu_request(req, !IN_GDB); + + error_hook = NULL; + pc->last_gdb_cmd = pc->cur_gdb_cmd; + pc->cur_gdb_cmd = 0; + pc->cur_req = NULL; +} + +/* + * help -g output + */ +void +dump_gdb_data(void) +{ + fprintf(fp, " prettyprint_arrays: %d\n", *gdb_prettyprint_arrays); + fprintf(fp, " prettyprint_structs: %d\n", *gdb_prettyprint_structs); + fprintf(fp, "repeat_count_threshold: %x\n", *gdb_repeat_count_threshold); + fprintf(fp, " stop_print_at_null: %d\n", *gdb_stop_print_at_null); + fprintf(fp, " print_max: %d\n", *gdb_print_max); + fprintf(fp, " output_radix: %d\n", *gdb_output_radix); + fprintf(fp, " output_format: "); + switch (*gdb_output_format) + { + case 'x': + fprintf(fp, "hex\n"); break; + case 'o': + fprintf(fp, "octal\n"); break; + case 0: + fprintf(fp, "decimal\n"); break; + } +} + +void +dump_gnu_request(struct gnu_request *req, int in_gdb) +{ + int others; + char buf[BUFSIZE]; + + if (pc->flags & KERNEL_DEBUG_QUERY) + return; + + console("%scommand: %d (%s)\n", in_gdb ? "GDB IN: " : "GDB OUT: ", + req->command, gdb_command_string(req->command, buf, TRUE)); + console("buf: %lx ", req->buf); + if (req->buf && ascii_string(req->buf)) + console(" \"%s\"", req->buf); + console("\n"); + console("fp: %lx ", req->fp); + + if (req->fp == pc->nullfp) + console("(pc->nullfp) "); + if (req->fp == pc->stdpipe) + console("(pc->stdpipe) "); + if (req->fp == pc->pipe) + console("(pc->pipe) "); + if (req->fp == pc->ofile) + console("(pc->ofile) "); + if (req->fp == pc->ifile) + console("(pc->ifile) "); + if (req->fp == pc->ifile_pipe) + console("(pc->ifile_pipe) "); + if (req->fp == pc->ifile_ofile) + console("(pc->ifile_ofile) "); + if (req->fp == pc->tmpfile) + console("(pc->tmpfile) "); + if (req->fp == pc->saved_fp) + console("(pc->saved_fp) "); + if (req->fp == pc->tmp_fp) + console("(pc->tmp_fp) "); + + console("flags: %lx (", req->flags); + others = 0; + if (req->flags & GNU_PRINT_LINE_NUMBERS) + console("%sGNU_PRINT_LINE_NUMBERS", others++ ? "|" : ""); + if (req->flags & GNU_FUNCTION_ONLY) + console("%sGNU_FUNCTION_ONLY", others++ ? "|" : ""); + if (req->flags & GNU_PRINT_ENUMERATORS) + console("%sGNU_PRINT_ENUMERATORS", others++ ? "|" : ""); + if (req->flags & GNU_RETURN_ON_ERROR) + console("%sGNU_RETURN_ON_ERROR", others++ ? "|" : ""); + if (req->flags & GNU_FROM_TTY_OFF) + console("%sGNU_FROM_TTY_OFF", others++ ? "|" : ""); + if (req->flags & GNU_NO_READMEM) + console("%sGNU_NO_READMEM", others++ ? "|" : ""); + if (req->flags & GNU_VAR_LENGTH_TYPECODE) + console("%sGNU_VAR_LENGTH_TYPECODE", others++ ? "|" : ""); + console(")\n"); + + console("addr: %lx ", req->addr); + console("addr2: %lx ", req->addr2); + console("count: %ld\n", req->count); + + if ((ulong)req->name > (ulong)PATCH_KERNEL_SYMBOLS_STOP) + console("name: \"%s\" ", req->name); + else + console("name: %lx ", (ulong)req->name); + console("length: %ld ", req->length); + console("typecode: %d\n", req->typecode); +#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) || defined(GDB_7_0) + console("typename: %s\n", req->typename); +#else + console("type_name: %s\n", req->type_name); +#endif + console("target_typename: %s\n", req->target_typename); + console("target_length: %ld ", req->target_length); + console("target_typecode: %d ", req->target_typecode); + console("is_typedef: %d ", req->is_typedef); + console("member: \"%s\" ", req->member); + console("member_offset: %ld\n", req->member_offset); + console("member_length: %ld\n", req->member_length); + console("member_typecode: %d\n", req->member_typecode); + console("value: %lx ", req->value); + console("tagname: \"%s\" ", req->tagname); + console("pc: %lx ", req->pc); + if (is_kernel_text(req->pc)) + console("(%s)", value_to_symstr(req->pc, buf, 0)); + console("\n"); + console("sp: %lx ", req->sp); + console("ra: %lx ", req->ra); + console("frame: %ld ", req->frame); + console("prevsp: %lx\n", req->prevsp); + console("prevpc: %lx ", req->prevpc); + console("lastsp: %lx ", req->lastsp); + console("task: %lx ", req->task); + console("debug: %lx\n", req->debug); + console("\n"); +} + +char * +gdb_command_string(int cmd, char *buf, int live) +{ + switch (cmd) + { + case GNU_PASS_THROUGH: + sprintf(buf, "GNU_PASS_THROUGH"); + break; + case GNU_DATATYPE_INIT: + sprintf(buf, "GNU_DATATYPE_INIT"); + break; + case GNU_DISASSEMBLE: + sprintf(buf, "GNU_DISASSEMBLE"); + break; + case GNU_GET_LINE_NUMBER: + sprintf(buf, "GNU_GET_LINE_NUMBER"); + break; + case GNU_GET_DATATYPE: + if (live) + sprintf(buf, "GNU_GET_DATATYPE[%s]", + pc->cur_req->name ? pc->cur_req->name : "?"); + else + sprintf(buf, "GNU_GET_DATATYPE"); + break; + case GNU_STACK_TRACE: + sprintf(buf, "GNU_STACK_TRACE"); + break; + case GNU_ALPHA_FRAME_OFFSET: + sprintf(buf, "GNU_ALPHA_FRAME_OFFSET"); + break; + case GNU_COMMAND_EXISTS: + sprintf(buf, "GNU_COMMAND_EXISTS"); + break; + case GNU_FUNCTION_NUMARGS: + sprintf(buf, "GNU_FUNCTION_NUMARGS"); + break; + case GNU_RESOLVE_TEXT_ADDR: + sprintf(buf, "GNU_RESOLVE_TEXT_ADDR"); + break; + case GNU_DEBUG_COMMAND: + sprintf(buf, "GNU_DEBUG_COMMAND"); + break; + case GNU_ADD_SYMBOL_FILE: + sprintf(buf, "GNU_ADD_SYMBOL_FILE"); + break; + case GNU_DELETE_SYMBOL_FILE: + sprintf(buf, "GNU_DELETE_SYMBOL_FILE"); + break; + case GNU_VERSION: + sprintf(buf, "GNU_VERSION"); + break; + case GNU_GET_SYMBOL_TYPE: + sprintf(buf, "GNU_GET_SYMBOL_TYPE"); + break; + case GNU_PATCH_SYMBOL_VALUES: + sprintf(buf, "GNU_PATCH_SYMBOL_VALUES"); + break; + case GNU_USER_PRINT_OPTION: + sprintf(buf, "GNU_USER_PRINT_OPTION"); + break; + case GNU_SET_CRASH_BLOCK: + sprintf(buf, "GNU_SET_CRASH_BLOCK"); + break; + case 0: + buf[0] = NULLCHAR; + break; + default: + sprintf(buf, "(?)\n"); + break; + } + + return buf; +} + +/* + * Restore known gdb state. + */ +void +restore_gdb_sanity(void) +{ + if (!(pc->flags & GDB_INIT)) + return; + + if (pc->output_radix) { + *gdb_output_radix = pc->output_radix; + *gdb_output_format = (*gdb_output_radix == 10) ? 0 : 'x'; + } + + *gdb_prettyprint_structs = 1; /* these may piss somebody off... */ + *gdb_repeat_count_threshold = 0x7fffffff; + + error_hook = NULL; + + if (st->flags & ADD_SYMBOL_FILE) { + error(INFO, + "%s\n gdb add-symbol-file command failed\n", + st->current->mod_namelist); + delete_load_module(st->current->mod_base); + st->flags &= ~ADD_SYMBOL_FILE; + } + + if (pc->cur_gdb_cmd) { + pc->last_gdb_cmd = pc->cur_gdb_cmd; + pc->cur_gdb_cmd = 0; + } +} + +/* + * Check whether string in args[0] is a valid gdb command. + */ +int +is_gdb_command(int merge_orig_args, ulong flags) +{ + int retval; + struct gnu_request *req; + + if (!args[0]) + return FALSE; + + if (STREQ(args[0], "Q")) { + args[0] = "q"; + return TRUE; + } + + if (is_restricted_command(args[0], flags)) + return FALSE; + + req = (struct gnu_request *)GETBUF(sizeof(struct gnu_request)); + req->buf = GETBUF(strlen(args[0])+1); + req->command = GNU_COMMAND_EXISTS; + req->name = args[0]; + req->flags = GNU_RETURN_ON_ERROR; + req->fp = pc->nullfp; + + gdb_interface(req); + + if (req->flags & GNU_COMMAND_FAILED) + retval = FALSE; + else + retval = req->value; + + FREEBUF(req->buf); + FREEBUF(req); + + if (retval && merge_orig_args) { + int i; + for (i = argcnt; i; i--) + args[i] = args[i-1]; + args[0] = "gdb"; + argcnt++; + } + + return retval; +} + +/* + * Check whether a command is on the gdb-prohibited list. + */ +static char *prohibited_list[] = { + "run", "r", "break", "b", "tbreak", "hbreak", "thbreak", "rbreak", + "watch", "rwatch", "awatch", "attach", "continue", "c", "fg", "detach", + "finish", "handle", "interrupt", "jump", "kill", "next", "nexti", + "signal", "step", "s", "stepi", "target", "thread", "until", "delete", + "clear", "disable", "enable", "condition", "ignore", "frame", + "select-frame", "f", "up", "down", "catch", "tcatch", "return", + "file", "exec-file", "core-file", "symbol-file", "load", "si", "ni", + "shell", + NULL /* must be last */ +}; + +static char *restricted_list[] = { + "define", "document", "while", "if", + NULL /* must be last */ +}; + +#define RESTRICTED_GDB_COMMAND \ + "restricted gdb command: %s\n%s\"%s\" may only be used in a .gdbinit file or in a command file.\n%sThe .gdbinit file is read automatically during %s initialization.\n%sOther user-defined command files may be read interactively during\n%s%s runtime by using the gdb \"source\" command.\n" + +static int +is_restricted_command(char *cmd, ulong flags) +{ + int i; + char *newline; + + for (i = 0; prohibited_list[i]; i++) { + if (STREQ(prohibited_list[i], cmd)) { + if (flags == RETURN_ON_ERROR) + return TRUE; + pc->curcmd = pc->program_name; + error(FATAL, "prohibited gdb command: %s\n", cmd); + } + } + + for (i = 0; restricted_list[i]; i++) { + if (STREQ(restricted_list[i], cmd)) { + if (flags == RETURN_ON_ERROR) + return TRUE; + newline = space(strlen(pc->program_name)+2); + pc->curcmd = pc->program_name; + error(FATAL, RESTRICTED_GDB_COMMAND, + cmd, newline, cmd, + newline, pc->program_name, + newline, newline, pc->program_name); + } + } + + return FALSE; +} + +/* + * Remove pipe/redirection stuff from the end of the command line. + */ +static void +strip_redirection(char *buf) +{ + char *p1, *p2; + + p1 = strstr_rightmost(buf, args[argcnt-1]); + p2 = p1 + strlen(args[argcnt-1]); + console("strip_redirection: [%s]\n", p2); + + if ((p1 = strpbrk(p2, "|!>"))) + *p1 = NULLCHAR; + + strip_ending_whitespace(buf); +} + +/* + * Command for passing strings directly to gdb. + */ +void +cmd_gdb(void) +{ + char buf[BUFSIZE]; + char **argv; + + argv = STREQ(args[0], "gdb") ? &args[1] : &args[0]; + + if (*argv == NULL) + cmd_usage(pc->curcmd, SYNOPSIS); + + if (STREQ(*argv, "set") && argv[1]) { + /* + * Intercept set commands in case something has to be done + * here or elsewhere. + */ + if (STREQ(argv[1], "gdb")) { + cmd_set(); + return; + } + if (STREQ(argv[1], "output-radix") && argv[2]) + pc->output_radix = stol(argv[2], FAULT_ON_ERROR, NULL); + } + + /* + * If the command is not restricted, pass it on. + */ + if (!is_restricted_command(*argv, FAULT_ON_ERROR)) { + if (STREQ(pc->command_line, "gdb")) { + strcpy(buf, &pc->orig_line[3]); + strip_beginning_whitespace(buf); + } else + strcpy(buf, pc->orig_line); + + if (pc->redirect & (REDIRECT_TO_FILE|REDIRECT_TO_PIPE)) + strip_redirection(buf); + + if (!gdb_pass_through(buf, NULL, GNU_RETURN_ON_ERROR)) + error(INFO, "gdb request failed: %s\n", buf); + } +} + +/* + * The gdb target_xfer_memory() has a hook installed to re-route + * all memory accesses back here; reads of 1 or 4 bytes come primarily + * from text disassembly requests, and are diverted to the text cache. + */ +int +gdb_readmem_callback(ulong addr, void *buf, int len, int write) +{ + char locbuf[SIZEOF_32BIT], *p1; + uint32_t *p2; + int memtype; + + if (write) + return FALSE; + + if (pc->cur_req->flags & GNU_NO_READMEM) + return TRUE; + + if (pc->curcmd_flags & MEMTYPE_UVADDR) + memtype = UVADDR; + else if (pc->curcmd_flags & MEMTYPE_FILEADDR) + memtype = FILEADDR; + else if (!IS_KVADDR(addr)) { + if (STREQ(pc->curcmd, "gdb") && + STRNEQ(pc->cur_req->buf, "x/")) { + memtype = UVADDR; + } else { + if (CRASHDEBUG(1)) + console("gdb_readmem_callback: %lx %d FAILED\n", + addr, len); + return FALSE; + } + } else + memtype = KVADDR; + + if (CRASHDEBUG(1)) + console("gdb_readmem_callback[%d]: %lx %d\n", + memtype, addr, len); + + if (memtype == FILEADDR) + return(readmem(pc->curcmd_private, memtype, buf, len, + "gdb_readmem_callback", RETURN_ON_ERROR)); + + switch (len) + { + case SIZEOF_8BIT: + p1 = (char *)buf; + if ((memtype == KVADDR) && + text_value_cache_byte(addr, (unsigned char *)p1)) + return TRUE; + + if (!readmem(addr, memtype, locbuf, SIZEOF_32BIT, + "gdb_readmem_callback", RETURN_ON_ERROR)) + return FALSE; + + *p1 = locbuf[0]; + if (memtype == KVADDR) { + p2 = (uint32_t *)locbuf; + text_value_cache(addr, *p2, 0); + } + return TRUE; + + case SIZEOF_32BIT: + if ((memtype == KVADDR) && text_value_cache(addr, 0, buf)) + return TRUE; + + if (!readmem(addr, memtype, buf, SIZEOF_32BIT, + "gdb_readmem callback", RETURN_ON_ERROR)) + return FALSE; + + if (memtype == KVADDR) + text_value_cache(addr, + (uint32_t)*((uint32_t *)buf), NULL); + return TRUE; + } + + return(readmem(addr, memtype, buf, len, + "gdb_readmem_callback", RETURN_ON_ERROR)); + +} + +/* + * Machine-specific line-number pc section range verifier. + */ +int +gdb_line_number_callback(ulong pc, ulong low, ulong high) +{ + if (machdep->verify_line_number) + return machdep->verify_line_number(pc, low, high); + + return TRUE; +} + +/* + * Prevent gdb from trying to translate and print pointers + * that are not kernel virtual addresses. + */ +int +gdb_print_callback(ulong addr) +{ + if (!addr) + return FALSE; + else + return IS_KVADDR(addr); +} + +/* + * Used by gdb_interface() to catch gdb-related errors, if desired. + */ +void +gdb_error_hook(void) +{ + char buf1[BUFSIZE]; + char buf2[BUFSIZE]; + int buffers; + + if (CRASHDEBUG(2)) { + sprintf(buf2, "\n"); + + if (CRASHDEBUG(5) && (buffers = get_embedded())) + sprintf(buf2, "(%d buffer%s in use)\n", + buffers, buffers > 1 ? "s" : ""); + + fprintf(stderr, "%s: returned via gdb_error_hook %s", + gdb_command_string(pc->cur_gdb_cmd, buf1, TRUE), buf2); + + console("%s: returned via gdb_error_hook %s", + gdb_command_string(pc->cur_gdb_cmd, buf1, TRUE), buf2); + } + +#ifdef GDB_7_6 + do_cleanups(all_cleanups()); +#else + do_cleanups(NULL); +#endif + + longjmp(pc->gdb_interface_env, 1); +} + + +/* + * gdb callback to access debug mode. + */ +int +gdb_CRASHDEBUG(ulong dval) +{ + if (CRASHDEBUG(dval)) + return TRUE; + + return (pc->cur_req && (pc->cur_req->debug >= dval)); +} + +static ulong +gdb_user_print_option_address(char *name) +{ + struct gnu_request request; + + request.command = GNU_USER_PRINT_OPTION; + request.name = name; + gdb_command_funnel(&request); + return request.addr; +} + +/* + * Try to set a crash scope block based upon the vaddr. + */ +int +gdb_set_crash_scope(ulong vaddr, char *arg) +{ + struct gnu_request request, *req = &request; + char name[BUFSIZE]; + struct load_module *lm; + + if (!is_kernel_text(vaddr)) { + error(INFO, "invalid text address: %s\n", arg); + return FALSE; + } + + if (module_symbol(vaddr, NULL, &lm, name, 0)) { + if (!(lm->mod_flags & MOD_LOAD_SYMS)) { + error(INFO, "attempting to find/load \"%s\" module debuginfo\n", + lm->mod_name); + if (!load_module_symbols_helper(lm->mod_name)) { + error(INFO, "cannot find/load \"%s\" module debuginfo\n", + lm->mod_name); + return FALSE; + } + } + } + + req->command = GNU_SET_CRASH_BLOCK; + req->addr = vaddr; + req->flags = 0; + req->addr2 = 0; + gdb_command_funnel(req); + + if (CRASHDEBUG(1)) + fprintf(fp, + "gdb_set_crash_scope: %s addr: %lx block: %lx\n", + req->flags & GNU_COMMAND_FAILED ? "FAILED" : "OK", + req->addr, req->addr2); + + if (req->flags & GNU_COMMAND_FAILED) { + error(INFO, + "gdb cannot find text block for address: %s\n", arg); + return FALSE; + } + + return TRUE; +} + +#ifndef ALPHA +/* + * Stub routine needed for resolution by non-alpha, modified gdb code. + */ +int +get_frame_offset(ulong pc) +{ + return (error(FATAL, + "get_frame_offset: invalid request for non-alpha systems!\n")); +} +#endif /* !ALPHA */ + + diff --git a/global_data.c b/global_data.c new file mode 100644 index 00000000..998aaae8 --- /dev/null +++ b/global_data.c @@ -0,0 +1,138 @@ +/* global_data.c - core analysis suite + * + * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2006, 2010, 2012-2013 David Anderson + * Copyright (C) 2002-2006, 2010, 2012-2013 Red Hat, Inc. 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. + */ + +#include "defs.h" + +/* + * Data output FILE pointer. The contents of fp are changed on the fly + * depending upon whether the output is going to stdout, redirected to a + * user-designated pipe or file, or to the "standard" scrolling pipe. + * Regardless of where it ends up, fprintf(fp, ...) is used throughout + * instead of printf(). + */ + +FILE *fp; + +/* + * The state of the program is kept in the program_context structure. + * Given that it's consulted so often, "pc" is globally available to + * quickly access the structure contents. + */ +struct program_context program_context = { 0 }; +struct program_context *pc = &program_context; + +/* + * The same thing goes for accesses to the frequently-accessed task_table, + * kernel_table, vm_table, symbol_table_data and machdep_table, making the + * "tt", "kt", "vt", "st" and "machdep" pointers globally available. + */ +struct task_table task_table = { 0 }; +struct task_table *tt = &task_table; + +struct kernel_table kernel_table = { 0 }; +struct kernel_table *kt = &kernel_table; + +struct vm_table vm_table = { 0 }; +struct vm_table *vt = &vm_table; + +struct symbol_table_data symbol_table_data = { 0 }; +struct symbol_table_data *st = &symbol_table_data; + +struct machdep_table machdep_table = { 0 }; +struct machdep_table *machdep = &machdep_table; + +/* + * Command functions are entered with the args[] array and argcnt value + * pre-set for issuance to getopt(). + */ + +char *args[MAXARGS]; /* argument array */ +int argcnt; /* argument count */ +int argerrs; /* argument error counter */ + +/* + * To add a new command, declare it in defs.h and enter it in this table. + */ + +struct command_table_entry linux_command_table[] = { + {"*", cmd_pointer, help_pointer, 0}, + {"alias", cmd_alias, help_alias, 0}, + {"ascii", cmd_ascii, help_ascii, 0}, + {"bt", cmd_bt, help_bt, REFRESH_TASK_TABLE}, + {"btop", cmd_btop, help_btop, 0}, + {"dev", cmd_dev, help_dev, 0}, + {"dis", cmd_dis, help_dis, MINIMAL}, + {"eval", cmd_eval, help_eval, MINIMAL}, + {"exit", cmd_quit, help_exit, MINIMAL}, + {"extend", cmd_extend, help_extend, MINIMAL}, + {"files", cmd_files, help_files, REFRESH_TASK_TABLE}, + {"foreach", cmd_foreach, help_foreach, REFRESH_TASK_TABLE}, + {"fuser", cmd_fuser, help_fuser, REFRESH_TASK_TABLE}, + {"gdb", cmd_gdb, help_gdb, REFRESH_TASK_TABLE}, + {"help", cmd_help, help_help, MINIMAL}, + {"ipcs", cmd_ipcs, help_ipcs, REFRESH_TASK_TABLE}, + {"irq", cmd_irq, help_irq, 0}, + {"kmem", cmd_kmem, help_kmem, 0}, + {"list", cmd_list, help__list, REFRESH_TASK_TABLE}, + {"log", cmd_log, help_log, MINIMAL}, + {"mach", cmd_mach, help_mach, 0}, + {"map", cmd_map, help_map, HIDDEN_COMMAND}, + {"mod", cmd_mod, help_mod, 0}, + {"mount", cmd_mount, help_mount, 0}, + {"net", cmd_net, help_net, REFRESH_TASK_TABLE}, + {"p", cmd_p, help_p, 0}, + {"ps", cmd_ps, help_ps, REFRESH_TASK_TABLE}, + {"pte", cmd_pte, help_pte, 0}, + {"ptob", cmd_ptob, help_ptob, 0}, + {"ptov", cmd_ptov, help_ptov, 0}, + {"q", cmd_quit, help_quit, MINIMAL}, + {"tree", cmd_tree, help_tree, REFRESH_TASK_TABLE}, + {"rd", cmd_rd, help_rd, MINIMAL}, + {"repeat", cmd_repeat, help_repeat, 0}, + {"runq", cmd_runq, help_runq, REFRESH_TASK_TABLE}, + {"search", cmd_search, help_search, 0}, + {"set", cmd_set, help_set, REFRESH_TASK_TABLE | MINIMAL}, + {"sig", cmd_sig, help_sig, REFRESH_TASK_TABLE}, + {"struct", cmd_struct, help_struct, 0}, + {"swap", cmd_swap, help_swap, 0}, + {"sym", cmd_sym, help_sym, MINIMAL}, + {"sys", cmd_sys, help_sys, REFRESH_TASK_TABLE}, + {"task", cmd_task, help_task, REFRESH_TASK_TABLE}, + {"test", cmd_test, NULL, HIDDEN_COMMAND}, + {"timer", cmd_timer, help_timer, 0}, + {"union", cmd_union, help_union, 0}, + {"vm", cmd_vm, help_vm, REFRESH_TASK_TABLE}, + {"vtop", cmd_vtop, help_vtop, REFRESH_TASK_TABLE}, + {"waitq", cmd_waitq, help_waitq, REFRESH_TASK_TABLE}, + {"whatis", cmd_whatis, help_whatis, 0}, + {"wr", cmd_wr, help_wr, 0}, +#if defined(S390) || defined(S390X) + {"s390dbf", cmd_s390dbf, help_s390dbf, 0}, +#endif + {(char *)NULL} +}; + +struct extension_table *extension_table = NULL; + +/* + * The offset_table and size_table structure contents are referenced + * through several OFFSET- and SIZE-related macros. The array_table + * is a shortcut used by get_array_length(). + */ +struct offset_table offset_table = { 0 }; +struct size_table size_table = { 0 }; +struct array_table array_table = { 0 }; diff --git a/help.c b/help.c new file mode 100644 index 00000000..91181522 --- /dev/null +++ b/help.c @@ -0,0 +1,8093 @@ +/* help.c - core analysis suite + * + * Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. + * Copyright (C) 2002-2013 David Anderson + * Copyright (C) 2002-2013 Red Hat, Inc. 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. + */ + +#include "defs.h" + +static void reshuffle_cmdlist(void); +static int sort_command_name(const void *, const void *); +static void display_commands(void); +static void display_copying_info(void); +static void display_warranty_info(void); +static void display_output_info(void); +static void display_input_info(void); +static void display_README(void); +static char *gnu_public_license[]; +static char *gnu_public_license_v3[]; +static char *version_info[]; +static char *output_info[]; +static char *input_info[]; +static char *README[]; +static void dump_registers(void); + +#define GPLv2 2 +#define GPLv3 3 + +#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) +static int GPL_version = GPLv2; +#else +static int GPL_version = GPLv3; +#endif + +static +char *program_usage_info[] = { + "", + "USAGE:", + "", + " crash [OPTION]... NAMELIST MEMORY-IMAGE (dumpfile form)", + " crash [OPTION]... [NAMELIST] (live system form)", + "", + "OPTIONS:", + "", + " NAMELIST", + " This is a pathname to an uncompressed kernel image (a vmlinux", + " file), or a Xen hypervisor image (a xen-syms file) which has", + " been compiled with the \"-g\" option. If using the dumpfile form,", + " a vmlinux file may be compressed in either gzip or bzip2 formats.", + "", + " MEMORY-IMAGE", + " A kernel core dump file created by the netdump, diskdump, LKCD", + " kdump, xendump or kvmdump facilities.", + "", + " If a MEMORY-IMAGE argument is not entered, the session will be", + " invoked on the live system, which typically requires root privileges", + " because of the device file used to access system RAM. By default, ", + " /dev/crash will be used if it exists. If it does not exist, then ", + " /dev/mem will be used; but if the kernel has been configured with ", + " CONFIG_STRICT_DEVMEM, then /proc/kcore will be used. It is permissible", + " to explicitly enter /dev/crash, /dev/mem or /proc/kcore.", + "", + " mapfile", + " If the NAMELIST file is not the same kernel that is running", + " (live system form), or the kernel that was running when the system", + " crashed (dumpfile form), then the System.map file of the original ", + " kernel should be entered on the command line.", + "", + " -h [option]", + " --help [option]", + " Without an option argument, display a crash usage help message.", + " If the option argument is a crash command name, the help page", + " for that command is displayed. If it is the string \"input\", a", + " page describing the various crash command line input options is", + " displayed. If it is the string \"output\", a page describing command", + " line output options is displayed. If it is the string \"all\", then", + " all of the possible help messages are displayed. After the help", + " message is displayed, crash exits.", + "", + " -s ", + " Silently proceed directly to the \"crash>\" prompt without displaying", + " any version, GPL, or crash initialization data during startup, and by", + " default, runtime command output is not passed to any scrolling command.", + "", + " -i file", + " Execute the command(s) contained in \"file\" prior to displaying ", + " the \"crash>\" prompt for interactive user input.", + "", + " -d num ", + " Set the internal debug level. The higher the number, the more", + " debugging data will be printed when crash initializes and runs.", + "", + " -S ", + " Use /boot/System.map as the mapfile.", + "", + " -e vi | emacs", + " Set the readline(3) command line editing mode to \"vi\" or \"emacs\". ", + " The default editing mode is \"vi\".", + "", + " -f ", + " Force the usage of a compressed vmlinux file if its original", + " name does not start with \"vmlinux\".", + "", + " -k ", + " Indicate that the NAMELIST file is an LKCD \"Kerntypes\" debuginfo file.", + "", + " -g [namelist]", + " Determine if a vmlinux or xen-syms namelist file contains debugging data.", + "", + " -t ", + " Display the system-crash timestamp and exit.", + "", + " -L ", + " Attempt to lock all of its virtual address space into memory by", + " calling mlockall(MCL_CURRENT|MCL_FUTURE) during initialization.", + " If the system call fails, an error message will be displayed,", + " but the session continues.", + "", + " -c tty-device", + " Open the tty-device as the console used for debug messages.", + "", + " -p page-size", + " If a processor's page size cannot be determined by the dumpfile, ", + " and the processor default cannot be used, use page-size.", + "", + " -m option=value", + " --machdep option=value", + " Pass an option and value pair to machine-dependent code. These", + " architecture-specific option/pairs should only be required in", + " very rare circumstances:", + "", + " X86_64:", + " physbase=", + " irq_eframe_link=", + " max_physmem_bits=", + " vm=orig (pre-2.6.11 virtual memory address ranges)", + " vm=2.6.11 (2.6.11 and later virtual memory address ranges)", + " vm=xen (Xen kernel virtual memory address ranges)", + " vm=xen-rhel4 (RHEL4 Xen kernel virtual address ranges)", + " PPC64:", + " vm=orig", + " vm=2.6.14 (4-level page tables)", + " IA64:", + " phys_start=", + " init_stack_size=", + " vm=4l (4-level page tables)", + " ARM:", + " physbase=", + "", + " -x ", + " Automatically load extension modules from a particular directory.", + " The directory is determined by the following order of precedence:", + "", + " (1) the directory specified in the CRASH_EXTENSIONS shell ", + " environment variable", + " (2) /usr/lib64/crash/extensions (64-bit architectures)", + " (3) /usr/lib/crash/extensions (32-bit architectures)", + " (4) the ./extensions subdirectory of the current directory", + "", + " --active", + " Track only the active task on each cpu.", + "", + " --buildinfo", + " Display the crash binary's build date, the user ID of the builder,", + " the hostname of the machine where the build was done, the target", + " architecture, the version number, and the compiler version.", + "", + " --memory_module modname", + " Use the modname as an alternative kernel module to the crash.ko", + " module that creates the /dev/crash device.", + "", + " --memory_device device", + " Use device as an alternative device to the /dev/crash, /dev/mem", + " or /proc/kcore devices.", + "", + " --log dumpfile", + " Dump the contents of the kernel log buffer. A kernel namelist", + " argument is not necessary, but the dumpfile must contain the", + " VMCOREINFO data taken from the original /proc/vmcore ELF header.", + "", + " --no_kallsyms", + " Do not use kallsyms-generated symbol information contained within", + " kernel module object files.", + "", + " --no_modules", + " Do not access or display any kernel module related information.", + "", + " --no_ikconfig", + " Do not attempt to read configuration data that was built into", + " kernels configured with CONFIG_IKCONFIG.", + "", + " --no_data_debug", + " Do not verify the validity of all structure member offsets and", + " structure sizes that it uses.", + "", + " --no_kmem_cache", + " Do not initialize the kernel's slab cache infrastructure, and", + " commands that use kmem_cache-related data will not work.", + "", + " --no_elf_notes", + " Do not use the registers from the ELF NT_PRSTATUS notes saved", + " in a compressed kdump header for backtraces.", + "", + " --kmem_cache_delay", + " Delay the initialization of the kernel's slab cache infrastructure", + " until it is required by a run-time command.", + "", + " --readnow", + " Pass this flag to the embedded gdb module, which will override", + " the two-stage strategy that it uses for reading symbol tables", + " from the NAMELIST. If module symbol tables are loaded during", + " runtime with the \"mod\" command, the same override will occur.", + "", + " --smp ", + " Specify that the system being analyzed is an SMP kernel.", + "", + " -v", + " --version", + " Display the version of the crash utility, the version of the", + " embedded gdb module, GPL information, and copyright notices.", + "", + " --cpus number", + " Specify the number of cpus in the SMP system being analyzed.", + "", + " --osrelease dumpfile", + " Display the OSRELEASE vmcoreinfo string from a kdump dumpfile", + " header.", + "", + " --hyper", + " Force the session to be that of a Xen hypervisor.", + "", + " --p2m_mfn pfn", + " When a Xen Hypervisor or its dom0 kernel crashes, the dumpfile", + " is typically analyzed with either the Xen hypervisor or the dom0", + " kernel. It is also possible to analyze any of the guest domU", + " kernels if the pfn_to_mfn_list_list pfn value of the guest kernel", + " is passed on the command line along with its NAMELIST and the ", + " dumpfile.", + "", + " --xen_phys_start physical-address", + " Supply the base physical address of the Xen hypervisor's text", + " and static data for older xendump dumpfiles that did not pass", + " that information in the dumpfile header.", + "", + " --zero_excluded", + " If a kdump dumpfile has been filtered to exclude various types of", + " non-essential pages, any attempt to read them will fail. With", + " this flag, reads from any of those pages will return zero-filled", + " memory.", + "", + " --no_panic", + " Do not attempt to find the task that was running when the kernel", + " crashed. Set the initial context to that of the \"swapper\" task", + " on cpu 0.", + "", + " --more ", + " Use /bin/more as the command output scroller, overriding the", + " default of /usr/bin/less and any settings in either ./.crashrc", + " or $HOME/.crashrc.", + "", + " --less ", + " Use /usr/bin/less as the command output scroller, overriding any", + " settings in either ./.crashrc or $HOME/.crashrc.", + "", + " --CRASHPAGER", + " Use the output paging command defined in the CRASHPAGER shell", + " environment variable, overriding any settings in either ./.crashrc ", + " or $HOME/.crashrc.", + "", + " --no_scroll", + " Do not pass run-time command output to any scrolling command.", + "", + " --no_strip", + " Do not strip cloned kernel text symbol names.", + "", + " --no_crashrc", + " Do not execute the commands in either $HOME/.crashrc or ./.crashrc.", + "", + " --mod directory", + " When loading the debuginfo data of kernel modules with the \"mod -S\"", + " command, search for their object files in directory instead of in ", + " the standard location.", + "", + " --reloc size", + " When analyzing live x86 kernels configured with a CONFIG_PHYSICAL_START ", + " value that is larger than its CONFIG_PHYSICAL_ALIGN value, then it will", + " be necessary to enter a relocation size equal to the difference between", + " the two values.", + "", + " --minimal", + " Bring up a session that is restricted to the log, dis, rd, sym,", + " eval, set and exit commands. This option may provide a way to", + " extract some minimal/quick information from a corrupted or truncated", + " dumpfile, or in situations where one of the several kernel subsystem ", + " initialization routines would abort the crash session.", + "", + " --kvmhost [32|64]", + " When examining an x86 KVM guest dumpfile, this option specifies", + " that the KVM host that created the dumpfile was an x86 (32-bit)", + " or an x86_64 (64-bit) machine, overriding the automatically", + " determined value.", + "", + " --kvmio ", + " override the automatically-calculated KVM guest I/O hole size.", + "", + "FILES:", + "", + " .crashrc", + " Initialization commands. The file can be located in the user's", + " HOME directory and/or the current directory. Commands found in", + " the .crashrc file in the HOME directory are executed before", + " those in the current directory's .crashrc file.", + "", + "ENVIRONMENT VARIABLES:", + "", + " EDITOR ", + " Command input is read using readline(3). If EDITOR is set to", + " emacs or vi then suitable keybindings are used. If EDITOR is", + " not set, then vi is used. This can be overridden by \"set vi\" or", + " \"set emacs\" commands located in a .crashrc file, or by entering", + " \"-e emacs\" on the crash command line.", + "", + " CRASHPAGER", + " If CRASHPAGER is set, its value is used as the name of the program", + " to which command output will be sent. If not, then command output", + " output is sent to \"/usr/bin/less -E -X\" by default.", + "", + " CRASH_MODULE_PATH", + " Specifies an alternative directory tree to search for kernel", + " module object files.", + "", + " CRASH_EXTENSIONS", + " Specifies a directory containing extension modules that will be", + " loaded automatically if the -x command line option is used.", + "", + NULL +}; + +void +program_usage(int form) +{ + if (form == SHORT_FORM) { + fprintf(fp, "\nUsage:\n\n"); + fprintf(fp, "%s\n%s\n", program_usage_info[3], + program_usage_info[4]); + fprintf(fp, "\nEnter \"%s -h\" for details.\n", + pc->program_name); + clean_exit(1); + } else { + FILE *scroll; + char *scroll_command; + char **p; + + if ((scroll_command = setup_scroll_command()) && + (scroll = popen(scroll_command, "w"))) + fp = scroll; + else + scroll = NULL; + + for (p = program_usage_info; *p; p++) { + fprintf(fp, *p, pc->program_name); + fprintf(fp, "\n"); + } + fflush(fp); + + if (scroll) + pclose(scroll); + + clean_exit(0); + } +} + + +/* + * Get an updated count of commands for subsequent help menu display, + * reshuffling the deck if this is the first time or if something's changed. + */ +void +help_init(void) +{ + struct command_table_entry *cp; + struct extension_table *ext; + + for (pc->ncmds = 0, cp = pc->cmd_table; cp->name; cp++) { + if (!(cp->flags & HIDDEN_COMMAND)) + pc->ncmds++; + } + + for (ext = extension_table; ext; ext = ext->next) { + for (cp = ext->command_table; cp->name; cp++) { + if (!(cp->flags & (CLEANUP|HIDDEN_COMMAND))) + pc->ncmds++; + } + } + + if (!pc->cmdlist) { + pc->cmdlistsz = pc->ncmds; + if ((pc->cmdlist = (char **) + malloc(sizeof(char *) * pc->cmdlistsz)) == NULL) + error(FATAL, + "cannot malloc command list space\n"); + } else if (pc->ncmds > pc->cmdlistsz) { + pc->cmdlistsz = pc->ncmds; + if ((pc->cmdlist = (char **)realloc(pc->cmdlist, + sizeof(char *) * pc->cmdlistsz)) == NULL) + error(FATAL, + "cannot realloc command list space\n"); + } + + reshuffle_cmdlist(); +} + +/* + * If the command list is modified during runtime, re-shuffle the list + * for proper help menu display. + */ +static void +reshuffle_cmdlist(void) +{ + int i, cnt; + struct command_table_entry *cp; + struct extension_table *ext; + + for (i = 0; i < pc->cmdlistsz; i++) + pc->cmdlist[i] = NULL; + + for (cnt = 0, cp = pc->cmd_table; cp->name; cp++) { + if (!(cp->flags & HIDDEN_COMMAND)) + pc->cmdlist[cnt++] = cp->name; + } + + for (ext = extension_table; ext; ext = ext->next) { + for (cp = ext->command_table; cp->name; cp++) { + if (!(cp->flags & (CLEANUP|HIDDEN_COMMAND))) + pc->cmdlist[cnt++] = cp->name; + } + } + + if (cnt > pc->cmdlistsz) + error(FATAL, "help table malfunction!\n"); + + qsort((void *)pc->cmdlist, (size_t)cnt, + sizeof(char *), sort_command_name); +} + + +/* + * The help list is in alphabetical order, with exception of the "q" command, + * which has historically always been the last command in the list. + */ + +static int +sort_command_name(const void *name1, const void *name2) +{ + char **s1, **s2; + + s1 = (char **)name1; + s2 = (char **)name2; + + if (STREQ(*s1, "q")) + return 1; + + return strcmp(*s1, *s2); +} + + +/* + * Get help for a command, to dump an internal table, or the GNU public + * license copying/warranty information. + */ +void +cmd_help(void) +{ + int c; + int oflag; + + oflag = 0; + + while ((c = getopt(argcnt, args, + "efNDdmM:ngcaBbHhkKsvVoptTzLxOr")) != EOF) { + switch(c) + { + case 'e': + dump_extension_table(VERBOSE); + return; + + case 'f': + dump_filesys_table(VERBOSE); + return; + + case 'n': + case 'D': + dumpfile_memory(DUMPFILE_MEM_DUMP); + return; + + case 'x': + dump_text_value_cache(VERBOSE); + return; + + case 'd': + dump_dev_table(); + return; + + case 'M': + dump_machdep_table(stol(optarg, FAULT_ON_ERROR, NULL)); + return; + case 'm': + dump_machdep_table(0); + return; + + case 'g': + dump_gdb_data(); + return; + + case 'N': + dump_net_table(); + return; + + case 'a': + dump_alias_data(); + return; + + case 'b': + dump_shared_bufs(); + return; + + case 'B': + dump_build_data(); + return; + + case 'c': + dump_numargs_cache(); + return; + + case 'H': + dump_hash_table(VERBOSE); + return; + + case 'h': + dump_hash_table(!VERBOSE); + return; + + case 'k': + dump_kernel_table(!VERBOSE); + return; + + case 'K': + dump_kernel_table(VERBOSE); + return; + + case 's': + dump_symbol_table(); + return; + + case 'V': + dump_vm_table(VERBOSE); + return; + + case 'v': + dump_vm_table(!VERBOSE); + return; + + case 'O': + dump_offset_table(NULL, TRUE); + return; + + case 'o': + oflag = TRUE; + break; + + case 'T': + dump_task_table(VERBOSE); + return; + + case 't': + dump_task_table(!VERBOSE); + return; + + case 'p': + dump_program_context(); + return; + + case 'z': + fprintf(fp, "help options:\n"); + fprintf(fp, " -a - alias data\n"); + fprintf(fp, " -b - shared buffer data\n"); + fprintf(fp, " -B - build data\n"); + fprintf(fp, " -c - numargs cache\n"); + fprintf(fp, " -d - device table\n"); + fprintf(fp, " -D - dumpfile contents/statistics\n"); + fprintf(fp, " -e - extension table data\n"); + fprintf(fp, " -f - filesys table\n"); + fprintf(fp, " -h - hash_table data\n"); + fprintf(fp, " -H - hash_table data (verbose)\n"); + fprintf(fp, " -k - kernel_table\n"); + fprintf(fp, " -K - kernel_table (verbose)\n"); + fprintf(fp, " -L - LKCD page cache environment\n"); + fprintf(fp, " -M machine specific\n"); + fprintf(fp, " -m - machdep_table\n"); + fprintf(fp, " -n - dumpfile contents/statistics\n"); + fprintf(fp, " -o - offset_table and size_table\n"); + fprintf(fp, " -p - program_context\n"); + fprintf(fp, " -r - dump registers from dumpfile header\n"); + fprintf(fp, " -s - symbol table data\n"); + fprintf(fp, " -t - task_table\n"); + fprintf(fp, " -T - task_table plus context_array\n"); + fprintf(fp, " -v - vm_table\n"); + fprintf(fp, " -V - vm_table (verbose)\n"); + fprintf(fp, " -x - text cache\n"); + return; + + case 'L': + dumpfile_memory(DUMPFILE_ENVIRONMENT); + return; + + case 'r': + dump_registers(); + return; + + default: + argerrs++; + break; + } + } + + if (argerrs) + cmd_usage(pc->curcmd, COMPLETE_HELP); + + if (!args[optind]) { + if (oflag) + dump_offset_table(NULL, FALSE); + else + display_help_screen(""); + return; + } + + do { + if (oflag) + dump_offset_table(args[optind], FALSE); + else + cmd_usage(args[optind], COMPLETE_HELP|MUST_HELP); + optind++; + } while (args[optind]); +} + +static void +dump_registers(void) +{ + if (pc->flags2 & QEMU_MEM_DUMP) { + dump_registers_for_qemu_mem_dump(); + return; + } else if (DISKDUMP_DUMPFILE()) { + dump_registers_for_compressed_kdump(); + return; + } else if (NETDUMP_DUMPFILE() || KDUMP_DUMPFILE()) { + dump_registers_for_elf_dumpfiles(); + return; + } + + error(FATAL, "-r option not supported on %s\n", + ACTIVE() ? "a live system" : "this dumpfile type"); +} + +/* + * Format and display the help menu. + */ + +void +display_help_screen(char *indent) +{ + int i, j, rows; + char **namep; + + help_init(); + + fprintf(fp, "\n%s", indent); + + rows = (pc->ncmds + (HELP_COLUMNS-1)) / HELP_COLUMNS; + + for (i = 0; i < rows; i++) { + namep = &pc->cmdlist[i]; + for (j = 0; j < HELP_COLUMNS; j++) { + fprintf(fp,"%-15s", *namep); + namep += rows; + if ((namep - pc->cmdlist) >= pc->ncmds) + break; + } + fprintf(fp,"\n%s", indent); + } + + fprintf(fp, "\n%s%s version: %-6s gdb version: %s\n", indent, + pc->program_name, pc->program_version, pc->gdb_version); + fprintf(fp, + "%sFor help on any command above, enter \"help \".\n", + indent); + fprintf(fp, "%sFor help on input options, enter \"help input\".\n", + indent); + fprintf(fp, "%sFor help on output options, enter \"help output\".\n", + indent); +#ifdef NO_LONGER_TRUE + fprintf(fp, "%sFor the most recent version: " + "http://www.missioncriticallinux.com/download\n\n", indent); +#else + fprintf(fp, "\n"); +#endif +} + +/* + * Used for generating HTML pages, dump the commands in the order + * they would be seen on the help menu, i.e., from left-to-right, row-by-row. + * Line ends are signaled with a "BREAK" string. + */ +static void +display_commands(void) +{ + int i, j, rows; + char **namep; + + help_init(); + rows = (pc->ncmds + (HELP_COLUMNS-1)) / HELP_COLUMNS; + + for (i = 0; i < rows; i++) { + namep = &pc->cmdlist[i]; + for (j = 0; j < HELP_COLUMNS; j++) { + fprintf(fp,"%s\n", *namep); + namep += rows; + if ((namep - pc->cmdlist) >= pc->ncmds) { + fprintf(fp, "BREAK\n"); + break; + } + } + } +} + + +/* + * Help data for a command must be formatted using the following template: + +"command-name", +"command description line", +"argument-usage line", +"description...", +"description...", +"description...", +NULL, + + * The first line is concatenated with the second line, and will follow the + * help command's "NAME" header. + * The first and third lines will also be concatenated, and will follow the + * help command's "SYNOPSIS" header. If the command has no arguments, enter + * a string consisting of a space, i.e., " ". + * The fourth and subsequent lines will follow the help command's "DESCRIPTION" + * header. + * + * The program name can be referenced by using the %%s format. The final + * entry in each command's help data string list must be a NULL. + */ + + +char *help_foreach[] = { +"foreach", +"display command data for multiple tasks in the system", +"[[pid | taskp | name | state | [kernel | user]] ...]\n" +" command [flag] [argument]", +" This command allows for a an examination of various kernel data associated", +" with any, or all, tasks in the system, without having to set the context", +" to each targeted task.\n", +" pid perform the command(s) on this PID.", +" taskp perform the command(s) on task referenced by this hexadecimal", +" task_struct pointer.", +" name perform the command(s) on all tasks with this name. If the", +" task name can be confused with a foreach command name, then", +" precede the name string with a \"\\\". If the name string is", +" enclosed within \"'\" characters, then the encompassed string", +" must be a POSIX extended regular expression that will be used", +" to match task names.", +" user perform the command(s) on all user (non-kernel) threads.", +" kernel perform the command(s) on all kernel threads.", +" active perform the command(s) on the active thread on each CPU.", +" state perform the command(s) on all tasks in the specified state, which", +" may be one of: RU, IN, UN, ST, ZO, TR, SW or DE.\n", +" If none of the task-identifying arguments above are entered, the command", +" will be performed on all tasks.\n", +" command select one or more of the following commands to be run on the tasks", +" selected, or on all tasks:\n", +" bt run the \"bt\" command (optional flags: -r -t -l -e -R -f -F", +" -o -s -x -d)", +" vm run the \"vm\" command (optional flags: -p -v -m -R -d -x)", +" task run the \"task\" command (optional flags: -R -d -x)", +" files run the \"files\" command (optional flag: -R)", +" net run the \"net\" command (optional flags: -s -S -R -d -x)", +" set run the \"set\" command", +" ps run the \"ps\" command (optional flags: -G -s -p -c -t -l -a", +" -g -r)", +" sig run the \"sig\" command (optional flag: -g)", +" vtop run the \"vtop\" command (optional flags: -c -u -k)\n", +" flag Pass this optional flag to the command selected.", +" argument Pass this argument to the command selected.", +" ", +" A header containing the PID, task address, cpu and command name will be", +" pre-pended before the command output for each selected task. Consult the", +" help page of each of the command types above for details.", +"\nEXAMPLES", +" Display the stack traces for all tasks:\n", +" %s> foreach bt", +" PID: 4752 TASK: c7680000 CPU: 1 COMMAND: \"xterm\"", +" #0 [c7681edc] schedule at c01135f6", +" (void)", +" #1 [c7681f34] schedule_timeout at c01131ff", +" (24)", +" #2 [c7681f64] do_select at c0132838", +" (5, c7681fa4, c7681fa0)", +" #3 [c7681fbc] sys_select at c0132dad", +" (5, 8070300, 8070380, 0, 0)", +" #4 [bffffb0c] system_call at c0109944", +" EAX: 0000008e EBX: 00000005 ECX: 08070300 EDX: 08070380 ", +" DS: 002b ESI: 00000000 ES: 002b EDI: 00000000 ", +" SS: 002b ESP: bffffadc EBP: bffffb0c ", +" CS: 0023 EIP: 402259ee ERR: 0000008e EFLAGS: 00000246 ", +" ", +" PID: 557 TASK: c5600000 CPU: 0 COMMAND: \"nfsd\"", +" #0 [c5601f38] schedule at c01135f6", +" (void)", +" #1 [c5601f90] schedule_timeout at c01131ff", +" (c5600000)", +" #2 [c5601fb8] svc_recv at c805363a", +" (c0096f40, c5602800, 7fffffff, 100, c65c9f1c)", +" #3 [c5601fec] (nfsd module) at c806e303", +" (c5602800, c5602800, c0096f40, 6c6e0002, 50)", +" #4 [c65c9f24] kernel_thread at c010834f", +" (0, 0, ext2_file_inode_operations)", +" ", +" PID: 824 TASK: c7c84000 CPU: 0 COMMAND: \"mingetty\"", +" ...\n", +" Display the task_struct structure for each \"bash\" command:\n", +" %s> foreach bash task", +" ...\n", +" Display the open files for all tasks:\n", +" %s> foreach files", +" ...\n", +" Display the state of tasks whose name contains a match to \"event.*\":\n", +" %s> foreach 'event.*' task -R state", +" PID: 99 TASK: ffff8804750d5500 CPU: 0 COMMAND: \"events/0\"", +" state = 1,", +" ", +" PID: 100 TASK: ffff8804750d4ac0 CPU: 1 COMMAND: \"events/1\"", +" state = 1,", +" ", +" PID: 101 TASK: ffff8804750d4080 CPU: 2 COMMAND: \"events/2\"", +" state = 1,", +" ...\n", +" Display the stack traces for all blocked (TASK_UNINTERRUPTIBLE) tasks:\n", +" %s> foreach UN bt", +" PID: 428 TASK: ffff880036b6c560 CPU: 1 COMMAND: \"jbd2/dm-1-8\"", +" #0 [ffff880035779a70] __schedule at ffffffff815df272", +" #1 [ffff880035779b08] schedule at ffffffff815dfacf", +" #2 [ffff880035779b18] io_schedule at ffffffff815dfb7f", +" #3 [ffff880035779b38] sleep_on_page at ffffffff81119a4e", +" #4 [ffff880035779b48] __wait_on_bit at ffffffff815e039f", +" #5 [ffff880035779b98] wait_on_page_bit at ffffffff81119bb8", +" #6 [ffff880035779be8] filemap_fdatawait_range at ffffffff81119ccc", +" #7 [ffff880035779cd8] filemap_fdatawait at ffffffff81119d8b", +" #8 [ffff880035779ce8] jbd2_journal_commit_transaction at ffffffff8123a99c", +" #9 [ffff880035779e58] kjournald2 at ffffffff8123ee7b", +" #10 [ffff880035779ee8] kthread at ffffffff8108fb9c", +" #11 [ffff880035779f48] kernel_thread_helper at ffffffff815ebaf4", +" ...\n", +NULL +}; + +char *help_ascii[] = { +"ascii", +"translate a hexadecimal string to ASCII", +"value ...", +" Translates 32-bit or 64-bit hexadecimal values to ASCII. If no argument", +" is entered, an ASCII chart is displayed.", +"\nEXAMPLES", +" Translate the hexadecimal value of 0x62696c2f7273752f to ASCII:", +"\n %s> ascii 62696c2f7273752f", +" 62696c2f7273752f: /usr/lib", +"\n Display an ASCII chart:", +"\n %s> ascii", +" ", +" 0 1 2 3 4 5 6 7", +" +-------------------------------", +" 0 | NUL DLE SP 0 @ P ' p", +" 1 | SOH DC1 ! 1 A Q a q", +" 2 | STX DC2 \" 2 B R b r", +" 3 | ETX DC3 # 3 C S c s", +" 4 | EOT DC4 $ 4 D T d t", +" 5 | ENQ NAK \% 5 E U e u", +" 6 | ACK SYN & 6 F V f v", +" 7 | BEL ETB ` 7 G W g w", +" 8 | BS CAN ( 8 H X h x", +" 9 | HT EM ) 9 I Y i y", +" A | LF SUB * : J Z j z", +" B | VT ESC + ; K [ k {", +" C | FF FS , < L \\ l |", +" D | CR GS _ = M ] m }", +" E | SO RS . > N ^ n ~", +" F | SI US / ? O - o DEL", +NULL +}; + +char *help_quit[] = { +"quit", +"exit this session", +" ", +" Bail out of the current %s session.", +"\nNOTE", +" This command is equivalent to the \"exit\" command.", +NULL +}; + +char *help_exit[] = { +"exit", +"exit this session", +" ", +" Bail out of the current %s session.", +"\nNOTE", +" This command is equivalent to the \"q\" command.", +NULL +}; + +char *help_help[] = { +"help", +"get help", +"[command | all] [-