# m_jvmdebug.h

Go to the documentation of this file.

    00001 ///
    00002 /// \file       m_jvmdebug.h
    00003 ///             Mode class for the JVMDebug mode
    00004 ///
    00005
    00006 /*
    00007     Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
    00008     Copyright (C) 2008-2009, Nicolas VIVIEN
    00009
    00010     This program is free software; you can redistribute it and/or modify
    00011     it under the terms of the GNU General Public License as published by
    00012     the Free Software Foundation; either version 2 of the License, or
    00013     (at your option) any later version.
    00014
    00015     This program is distributed in the hope that it will be useful,
    00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00018
    00019     See the GNU General Public License in the COPYING file at the
    00020     root directory of this project for more details.
    00021 */
    00022
    00023 #ifndef __BARRY_M_JVMDEBUG_H__
    00024 #define __BARRY_M_JVMDEBUG_H__
    00025
    00026 #include "dll.h"
    00027 #include "m_mode_base.h"
    00028 #include "socket.h"
    00029 #include "record.h"
    00030 #include "data.h"
    00031
    00032 namespace Barry {
    00033
    00034 // forward declarations
    00035 class Parser;
    00036 class Builder;
    00037 class Controller;
    00038
    00039 class JVMModulesEntry;
    00040 class JVMThreadsEntry;
    00041
    00042
    00043 class BXEXPORT JVMModulesList : public std::vector<JVMModulesEntry>
    00044 {
    00045 public:
    00046         typedef std::vector<JVMModulesEntry>            base_type;
    00047         typedef base_type::iterator                     iterator;
    00048         typedef base_type::const_iterator               const_iterator;
    00049
    00050 public:
    00051         void Parse(const Data &entry_packet);
    00052
    00053         void Dump(std::ostream &os) const;
    00054 };
    00055 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JVMModulesList &list) {
    00056         list.Dump(os);
    00057         return os;
    00058 }
    00059
    00060
    00061 class BXEXPORT JVMModulesEntry
    00062 {
    00063 public:
    00064         uint32_t        Id;
    00065         uint32_t        UniqueID;
    00066         std::string     Name;
    00067
    00068 public:
    00069         void Dump(std::ostream &os) const;
    00070 };
    00071
    00072
    00073 class BXEXPORT JVMThreadsList : public std::vector<JVMThreadsEntry>
    00074 {
    00075 public:
    00076         typedef std::vector<JVMThreadsEntry>            base_type;
    00077         typedef base_type::iterator                     iterator;
    00078         typedef base_type::const_iterator               const_iterator;
    00079
    00080 public:
    00081         void Parse(const Data &entry_packet);
    00082
    00083         void Dump(std::ostream &os) const;
    00084 };
    00085 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const JVMThreadsList &list) {
    00086         list.Dump(os);
    00087         return os;
    00088 }
    00089
    00090
    00091 class BXEXPORT JVMThreadsEntry
    00092 {
    00093 public:
    00094         uint32_t        Id;
    00095         uint8_t         Byte;
    00096         uint32_t        Address;
    00097         uint32_t        Unknown01;      // FIXME - perhaps should not expose
    00098                                         // these to the app level, until we
    00099                                         // have a name for them, since they
    00100                                         // might change without notice
    00101         uint32_t        Unknown02;
    00102         uint32_t        Unknown03;
    00103         uint32_t        Unknown04;
    00104         uint32_t        Unknown05;
    00105         uint32_t        Unknown06;
    00106
    00107 public:
    00108         void Dump(std::ostream &os, int num) const;
    00109 };
    00110
    00111
    00112 namespace Mode {
    00113
    00114 //
    00115 // JVMDebug class
    00116 //
    00117 /// The main interface class to the java program debugger protocol
    00118 ///
    00119 /// To use this class, use the following steps:
    00120 ///
    00121 ///     - Create a Controller object (see Controller class for more details)
    00122 ///     - Create this Mode::JVMDebug object, passing in the Controller
    00123 ///             object during construction
    00124 ///     - Call Open() to open database socket and finish constructing.
    00125 ///
    00126 class BXEXPORT JVMDebug : public Mode
    00127 {
    00128 private:
    00129         bool m_Attached;
    00130
    00131 protected:
    00132         void ThrowJVMError(const std::string &msg, uint8_t cmd);
    00133
    00134         //////////////////////////////////
    00135         // overrides
    00136
    00137         virtual void OnOpen();
    00138
    00139 public:
    00140         JVMDebug(Controller &con);
    00141         ~JVMDebug();
    00142
    00143         //////////////////////////////////
    00144         // API
    00145         void Close();
    00146
    00147         void Attach();
    00148         void Detach();
    00149
    00150         // mid-attachment operations
    00151         void Unknown01();       // FIXME - make these into a proper API, or
    00152                                 // hide under protected:
    00153         void Unknown02();
    00154         void Unknown03();
    00155         void Unknown04();
    00156         void Unknown05();
    00157         void Unknown06();
    00158         void Unknown07();
    00159         void Unknown08();
    00160         void Unknown09();
    00161         void Unknown10();
    00162         void GetModulesList(JVMModulesList &mylist);
    00163         void GetThreadsList(JVMThreadsList &mylist);
    00164         int GetConsoleMessage(std::string &msg);
    00165         bool GetStatus(int &status);
    00166         bool WaitStatus(int &status);
    00167         void Go();
    00168         void Stop();
    00169 };
    00170
    00171 }} // namespace Barry::Mode
    00172
    00173 #endif
    00174