• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

CoreUtils.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026    CoreUtils.h
00027 
00028    Description:  Automated processing of core files on Sparc & Linux
00029  ****************************************************************************/
00030 
00031 #ifndef _CORE_UTILS_H_
00032 #define _CORE_UTILS_H_
00033 
00034 #if defined(linux)
00035 #include <stdio.h>
00036 #include <sys/procfs.h>
00037 #include <unistd.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <math.h>
00041 #include <assert.h>
00042 #include <elf.h>
00043 #include "DynArray.h"
00044 
00045 #define SP_REGNUM 15            /* Contains address of top of stack USP */
00046 #define PC_REGNUM 12            /* Contains program counter EIP */
00047 #define FP_REGNUM 5             /* Virtual frame pointer EBP */
00048 #define NO_OF_ARGS 10           /* The argument depth upto which we would be looking into
00049                                    the stack */
00050 
00051 // contains local and in registers, frame pointer, and stack base
00052 struct core_stack_state
00053 {
00054   intptr_t framep;                   //int stkbase;
00055   intptr_t pc;
00056   intptr_t arg[NO_OF_ARGS];
00057 };
00058 #endif  // linux check
00059 
00060 #if defined(darwin) || defined(freebsd) || defined(solaris) || defined(openbsd) // FIXME: solaris x86
00061 #include <stdio.h>
00062 #include <unistd.h>
00063 #include <stdlib.h>
00064 #include <string.h>
00065 #include <math.h>
00066 #include <assert.h>
00067 
00068 #define NO_OF_ARGS 10           /* The argument depth upto which we would be looking into
00069                                    the stack */
00070 
00071 // contains local and in registers, frame pointer, and stack base
00072 struct core_stack_state
00073 {
00074   intptr_t framep;                   //int stkbase;
00075   intptr_t pc;
00076   intptr_t arg[NO_OF_ARGS];
00077 };
00078 #endif  /* darwin || freebsd || solaris */
00079 
00080 // to be sorted by virtual address
00081 struct memTable
00082 {
00083   intptr_t vaddr;
00084   intptr_t offset;
00085   intptr_t fsize;
00086 };
00087 
00088 typedef void (*StuffTest_f) (void *);
00089 
00090 class HttpSM;
00091 class HTTPHdr;
00092 class HdrHeap;
00093 
00094 class EThread;
00095 class UnixNetVConnection;
00096 
00097 class CoreUtils
00098 {
00099 public:
00100 
00101   /**********************************************************************
00102   * purpose: finds the index of the virtual address or finds what the
00103   *          index should be if the virtual address is not there
00104   * inputs: int vaddr, int upper, int lower
00105   * outputs: returns the index of the vaddr or the index after where it
00106   *          should be
00107   * notes: upper and lower stands for the lowest and highest indices
00108   *        the function should search between
00109   **********************************************************************/
00110   static intptr_t find_vaddr(intptr_t vaddr, intptr_t upper, intptr_t lower);
00111 
00112   /**********************************************************************
00113   * purpose: function used to build the virtual address table
00114   * inputs: int vaddr1, int offset1, int fsize1
00115   * outputs: none
00116   **********************************************************************/
00117   static void insert_table(intptr_t vaddr1, intptr_t offset1, intptr_t fsize1);
00118 
00119   /**********************************************************************
00120   * purpose: fills the given buffer with characters from the beginning
00121   *          of the given memory section
00122   * inputs: int vaddr, int length, char* buf, FILE *fp
00123   * outputs: returns -1 on read error or 1 if successful
00124   **********************************************************************/
00125   static intptr_t read_core_memory(intptr_t vaddr, intptr_t length, char *buf, FILE * fp);
00126 
00127   /**********************************************************************
00128   * purpose: fills the given buffer with characters from the beginning
00129   *          of the given memory section + given offset
00130   * inputs: int offset, int vaddr, int length, char* buf, FILE *fp
00131   * outputs: returns -1 on read error or 1 if successful
00132   **********************************************************************/
00133   static intptr_t read_core_memory(intptr_t offset, intptr_t vaddr, intptr_t length, char *buf, FILE * fp);
00134 
00135   /**********************************************************************
00136   * purpose: fills the buffer with num of given bytes from the
00137   *          beginning of the memory section
00138   * inputs: int vaddr, int bytes, char* buf
00139   * outputs: returns -1 on read error or num of bytes read
00140   **********************************************************************/
00141   static intptr_t read_from_core(intptr_t vaddr, intptr_t bytes, char *buf);
00142 
00143   /**********************************************************************
00144   * purpose: beats the heck outta me
00145   * inputs: int vaddr, int bytes, HdrHeap h
00146   * outputs: returns -1 on read error or num of bytes read
00147   **********************************************************************/
00148   static intptr_t read_heap_header(intptr_t vaddr, intptr_t bytes, HdrHeap h);
00149 
00150   /**********************************************************************
00151   * purpose: returns the active lwp id
00152   * inputs: none
00153   * outputs: returns the active lwp id
00154   **********************************************************************/
00155 
00156   /**********************************************************************
00157   * purpose: returns the base core_stack_state for the given thread id
00158   * inputs: int threadId, core_stack_state* coress
00159   * outputs: returns the base core_stack_state for the given thread id
00160   **********************************************************************/
00161 #if defined(linux)
00162   static void get_base_frame(intptr_t framep, core_stack_state * coress);
00163 #endif
00164 
00165   /**********************************************************************
00166   * purpose: returns the core_stack_state of the next frame up
00167   * inputs: core_stack_state* coress
00168   * outputs: returns 0 if current frame is already at the top of the stack
00169   *          or returns 1 and moves up the stack once
00170   **********************************************************************/
00171   static int get_next_frame(core_stack_state * coress);
00172 
00173   /**********************************************************************
00174   * purpose: loop ups over local & in registers on the stack and calls
00175   *            f on all of them
00176   * inputs: none
00177   * outputs: none
00178   **********************************************************************/
00179   static void find_stuff(StuffTest_f f);
00180 
00181   /**********************************************************************
00182   * purpose: tests whether a given register is an HttpSM
00183   * inputs: reg_type t, int i, core_stack_state coress
00184   * outputs: none
00185   **********************************************************************/
00186   static void test_HttpSM(void *);
00187   static void test_HttpSM_from_tunnel(void *);
00188 
00189   /**********************************************************************
00190   * purpose: prints out info about a give HttpSM
00191   * inputs: HttpSM* core_ptr (ptr to http_sm in core)
00192   * outputs: none
00193   **********************************************************************/
00194   static void process_HttpSM(HttpSM * core_ptr);
00195   static void process_EThread(EThread * eth_test);
00196   static void process_NetVC(UnixNetVConnection * eth_test);
00197 
00198   /**********************************************************************
00199   * purpose: dumps the given state machine's history
00200   * inputs: HttpSM* hsm
00201   * outputs: none
00202   **********************************************************************/
00203   static void dump_history(HttpSM * hsm);
00204 
00205   /**********************************************************************
00206   * purpose: fills in the given HTTPHdr * live_hdr with live information
00207   *          take from core_hdr the core file
00208   * inputs: HTTPHdr* core_hdr, HTTPHdr* live_hdr
00209   * outputs: -1 on failure or total bytes in the header heaps
00210   **********************************************************************/
00211   static int load_http_hdr(HTTPHdr * core_hdr, HTTPHdr * live_hdr);
00212 
00213   /**********************************************************************
00214   * purpose: loads the http hdr from handle h in the core file
00215   * inputs: HTTPHdr* h, char* name
00216   * outputs: none
00217   **********************************************************************/
00218   static void print_http_hdr(HTTPHdr * h, const char *name);
00219 
00220   /**********************************************************************
00221   * purpose: loads a null terminated string from the core file
00222   * inputs: core file string address
00223   * outputs: char* pointing to live string. call deallocs via ats_free()
00224   ***********************************************************************/
00225   static char *load_string(const char *addr);
00226 
00227   static void test_HdrHeap(void *arg);
00228 };
00229 
00230 
00231 // parses the core file
00232 void process_core(char *fname);
00233 
00234 #endif /* _core_utils_h_ */

Generated by  doxygen 1.7.1