etp-commands

来自「OTP是开放电信平台的简称」· 代码 · 共 1,993 行 · 第 1/4 页

TXT
1,993
字号
## ``The contents of this file are subject to the Erlang Public License,## Version 1.1, (the "License"); you may not use this file except in## compliance with the License. You should have received a copy of the## Erlang Public License along with this software. If not, it can be## retrieved via the world wide web at http://www.erlang.org/.## ## Software distributed under the License is distributed on an "AS IS"## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See## the License for the specific language governing rights and limitations## under the License.## ## The Initial Developer of the Original Code is Ericsson Utvecklings AB.## Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings## AB. All Rights Reserved.''## ##     $Id$############################################################################### Help commands# define etp-help  help etp-helpenddocument etp-help%---------------------------------------------------------------------------% etp-help% % Same as "help etp-help"% % Emulator Toolbox for Pathologists% - GDB commad toolbox for analyzing core dumps form the % Erlang emulator (BEAM).% % Should work for 32-bit erts-5.2/R9B, ...% % The commands are prefixed with:%   etp:  Acronym for erts-term-print%   etpf: Acronym for erts-term-print-flat% % User commands (these have help themselves):% % Most useful:%   etp, etpf% % Useful for doing step-by-step traversal of lists and tuples after % calling the toplevel command etpf:%   etpf-cons, etpf-boxed, % % Special commands for not really terms:%   etp-mfa, etp-cp, %   etp-msgq, etpf-msgq, %   etp-stacktrace, etp-stackdump, etpf-stackdump, etp-dictdump%   etp-offheapdump, etpf-offheapdump,%   etp-search-heaps, etp-search-alloc,%   etp-ets-tables, etp-ets-tabledump%% Complex commands that use the Erlang support module.%   etp-overlapped-heaps, etp-chart, etp-chart-start, etp-chart-end% % Erlang support module handling commands:%   etp-run%% Parameter handling commands:%   etp-show, etp-set-max-depth, etp-set-max-string-length% % Other commands you may find in this toolbox are suffixed -1, -2, ...% and are internal; not for the console user.% % The Erlang support module requires `erl' and `erlc' in the path.% The compiled "erl_commands.beam" file is stored in the current% working directory, so it is thereby in the search path of `erl'.% % These are just helpful commands when analyzing core dumps, but% you will not get away without knowing the gory details of the% tag bits. Do not forget about the e.g p, p/x, x and x/4x commands.%% Execution speed of user defined gdb commands is not lightning fast.% It may well take half a minute do dump a complex term with the default% max depth values on our old Sparc Ultra-10's.%% To use the Erlang support module, the environment variable ROOTDIR% must be set to the toplevel installation directory of Erlang/OTP,% so the etp-commands file becomes:%     $ROOTDIR/erts/etc/unix/etp-commands% Also, erl and erlc must be in the path.%---------------------------------------------------------------------------end############################################################################# Toplevel commands# define etp# Args: Eterm## Reentrant#  etp-1 ((Eterm)($arg0)) 0  printf ".\n"enddocument etp%---------------------------------------------------------------------------% etp Eterm% % Takes a toplevel Erlang term and prints the whole deep term% very much as in Erlang itself. Up to a max depth. See etp-show.%---------------------------------------------------------------------------enddefine etp-1# Args: Eterm, int depth## Reentrant#  if (($arg0) & 0x3) == 1    # Cons pointer    if $etp_flat      printf "<etpf-cons %#x>", ($arg0)    else      etp-list-1 ($arg0) ($arg1)    end  else    if (($arg0) & 0x3) == 2      if $etp_flat        printf "<etpf-boxed %#x>", ($arg0)      else        etp-boxed-1 ($arg0) ($arg1)      end    else      if (($arg0) & 0x3) == 3        etp-immediate-1 ($arg0)      else        # (($arg0) & 0x3) == 0        if (($arg0) == 0x0)          printf "<the non-value>"        else          if (($arg0) == 0x4)            printf "<the non-value debug>"          else            etp-cp-1 ($arg0)          end        end      end    end  endenddefine etpf# Args: Eterm## Non-reentrant  set $etp_flat = 1  etp-1 ((Eterm)($arg0))  set $etp_flat = 0  printf ".\n"enddocument etpf%---------------------------------------------------------------------------% etpf Eterm% % Takes a toplevel Erlang term and prints it is. If it is a deep term % print which command to use to traverse down one level.%---------------------------------------------------------------------------end############################################################################# Commands for nested terms. Some are recursive.#define etp-list-1# Args: Eterm cons_cell, int depth## Reentrant#  if (($arg0) & 0x3) != 0x1    printf "#NotCons<%#x>", ($arg0)  else    # Cons pointer    if $etp_chart      etp-chart-entry-1 ($arg0) ($arg1) 2    end    etp-list-printable-1 ($arg0) ($arg1)    if !$etp_list_printable      # Print normal list      printf "["      etp-list-2 ($arg0) (($arg1)+1)    end  endenddefine etp-list-printable-1# Args: Eterm list, int depth## Non-reentrant## Returns: $etp_list_printable#  if (($arg0) & 0x3) != 0x1    printf "#NotCons<%#x>", ($arg0)  else    # Loop to check if it is a printable string    set $etp_list_p = ($arg0)    set $etp_list_printable = ($etp_list_p != $etp_nil)    set $etp_list_i = 0    while ($etp_list_p != $etp_nil) && \          ($etp_list_i < $etp_max_string_length) && \          $etp_list_printable      if ($etp_list_p & 0x3) == 0x1        # Cons pointer        set $etp_list_n = ((Eterm*)($etp_list_p & ~0x3))[0]        if ($etp_list_n & 0xF) == 0xF          etp-ct-printable-1 ($etp_list_n>>4)          if $etp_ct_printable            # Printable            set $etp_list_p = ((Eterm*)($etp_list_p & ~0x3))[1]            set $etp_list_i++          else            set $etp_list_printable = 0          end        else          set $etp_list_printable = 0        end      else        set $etp_list_printable = 0      end    end    #    if $etp_list_printable  	# Print printable string  	printf "\""      set $etp_list_p = ($arg0)      set $etp_list_i = 0      while $etp_list_p != $etp_nil        set $etp_list_n = ((Eterm*)($etp_list_p & ~0x3))[0]        etp-char-1 ($etp_list_n>>4) '"'        set $etp_list_p = ((Eterm*)($etp_list_p & ~0x3))[1]        set $etp_list_i++        if $etp_list_p == $etp_nil          printf "\""        else          if $etp_list_i >= $etp_max_string_length            set $etp_list_p = $etp_nil            printf "\"++[...]"          else            if $etp_chart              etp-chart-entry-1 ($arg0) (($arg1)+$etp_list_i) 2            end          end        end      end    end  endenddefine etp-list-2# Args: Eterm cons_cell, int depth## Reentrant#  if (($arg0) & 0x3) != 0x1    printf "#NotCons<%#x>", ($arg0)  else    # Cons pointer    if ($arg1) >= $etp_max_depth      printf "...]"    else      etp-1 (((Eterm*)(($arg0)&~0x3))[0]) (($arg1)+1)      if ((Eterm*)(($arg0) & ~0x3))[1] == $etp_nil        # Tail is []        printf "]"      else        if $etp_chart          etp-chart-entry-1 ($arg0) ($arg1) 2        end        if (((Eterm*)(($arg0)&~0x3))[1]&0x3) == 0x1          # Tail is cons cell          printf ","          etp-list-2 (((Eterm*)(($arg0)&~0x3))[1]) (($arg1)+1)        else          # Tail is other term          printf "|"          etp-1 (((Eterm*)(($arg0)&~0x3))[1]) (($arg1)+1)          printf "]"        end      end    end  endenddefine etpf-cons# Args: Eterm## Reentrant capable#  if ((Eterm)($arg0) & 0x3) != 0x1    printf "#NotCons<%#x>", ($arg0)  else    # Cons pointer    set $etp_flat = 1    printf "["    etp-1 (((Eterm*)((Eterm)($arg0)&~0x3))[0])    printf "|"    etp-1 (((Eterm*)((Eterm)($arg0)&~0x3))[1])    printf "]\n"    set $etp_flat = 0  endenddocument etpf-cons%---------------------------------------------------------------------------% etpf-cons Eterm% % Takes a Cons ptr and prints the Car and Cdr cells with etpf (flat).%---------------------------------------------------------------------------enddefine etp-boxed-1# Args: Eterm, int depth## Reentrant#  if (($arg0) & 0x3) != 0x2    printf "#NotBoxed<%#x>", ($arg0)  else    if (((Eterm*)(($arg0) & ~0x3))[0] & 0x3) != 0x0      if $etp_chart        etp-chart-entry-1 (($arg0)&~0x3) ($arg1) 1      end      printf "#BoxedError<%#x>", ($arg0)    else      if $etp_chart        etp-chart-entry-1 (($arg0)&~0x3) ($arg1) \                          ((((Eterm*)(($arg0)&~0x3))[0]>>6)+1)      end      if (((Eterm*)(($arg0) & ~0x3))[0] & 0x3f) == 0x0        printf "{"        etp-array-1 ((Eterm*)(($arg0)&~0x3)) ($arg1) ($arg1) \                    1 ((((Eterm*)(($arg0)&~0x3))[0]>>6)+1) '}'      else        etp-boxed-immediate-1 ($arg0)      end    end  endenddefine etp-boxed-immediate-1# Args: Eterm, int depth## Non-reentrant#  if (($arg0) & 0x3) != 0x2    printf "#NotBoxed<%#x>", ($arg0)  else    if (((Eterm*)(($arg0) & ~0x3))[0] & 0x3) != 0x0      printf "#BoxedError<%#x>", ($arg0)    else      set $etp_boxed_immediate_p = (Eterm*)(($arg0) & ~0x3)      set $etp_boxed_immediate_h = ($etp_boxed_immediate_p[0] >> 2) & 0xF      if $etp_boxed_immediate_h == 0xC        etp-extpid-1 ($arg0)      else        if $etp_boxed_immediate_h == 0xD          etp-extport-1 ($arg0)        else          if ($etp_boxed_immediate_h == 0x2) || \             ($etp_boxed_immediate_h == 0x3)            etp-bignum-1 ($arg0)          else            if ($etp_boxed_immediate_h == 0x6)              etp-float-1 ($arg0)            else              if ($etp_boxed_immediate_h == 0x4)                etp-ref-1 ($arg0)              else                if ($etp_boxed_immediate_h == 0xE)                  etp-extref-1 ($arg0)                else                  # Hexdump the rest                  if ($etp_boxed_immediate_h == 0x5)                    printf "#Fun<"                  else                    if ($etp_boxed_immediate_h == 0x8)                      printf "#RefcBinary<"                    else                    if ($etp_boxed_immediate_h == 0x9)                      printf "#HeapBinary<"                    else                    if ($etp_boxed_immediate_h == 0xA)                      printf "#SubBinary<"                    else                      printf "#Header%X<", $etp_boxed_immediate_h                    end		  end		  end                  end                  set $etp_boxed_immediate_arity = $etp_boxed_immediate_p[0]>>6                  while $etp_boxed_immediate_arity > 0                    set $etp_boxed_immediate_p++                    if $etp_boxed_immediate_arity > 1                      printf "%#x,", *$etp_boxed_immediate_p                    else                      printf "%#x", *$etp_boxed_immediate_p        	      if ($etp_boxed_immediate_h == 0xA)                        set $etp_boxed_immediate_p++		    	printf ":%#x", *$etp_boxed_immediate_p		      end		      printf ">"                    end                    set $etp_boxed_immediate_arity--                  end                  # End of hexdump                end              end            end          end        end      end    end  endenddefine etpf-boxed# Args: Eterm## Non-reentrant#  set $etp_flat = 1  etp-boxed-1 ((Eterm)($arg0)) 0  set $etp_flat = 0  printf ".\n"enddocument etpf-boxed%---------------------------------------------------------------------------% etpf-boxed Eterm% % Take a Boxed ptr and print the contents in one level using etpf (flat).%---------------------------------------------------------------------------enddefine etp-array-1# Args: Eterm* p, int depth, int width, int pos, int size, int end_char## Reentrant#  if ($arg3) < ($arg4)    if (($arg1) < $etp_max_depth) && (($arg2) < $etp_max_depth)      etp-1 (($arg0)[($arg3)]) (($arg1)+1)      if (($arg3) + 1) != ($arg4)        printf ","      end      etp-array-1 ($arg0) ($arg1) (($arg2)+1) (($arg3)+1) ($arg4) ($arg5)    else      printf "...%c", ($arg5)    end  else    printf "%c", ($arg5)  endend#define etpa-1## Args: Eterm, int depth, int index, int arity#### Reentrant###  if ($arg1) >= $etp_max_depth+$etp_max_string_length#    printf "%% Max depth for term %d\n", $etp_chart_id#  else#    if ($arg2) < ($arg3)#      etp-1 (((Eterm*)(($arg0)&~0x3))[$arg2]) (($arg1)+1)#      etpa-1 ($arg0) (($arg1)+1) (($arg2)+1) ($arg3)#    end#  end#end############################################################################# Commands for non-nested terms. Recursion leaves. Some call other leaves.#define etp-immediate-1# Args: Eterm## Reentrant capable#  if (($arg0) & 0x3) != 0x3    printf "#NotImmediate<%#x>", ($arg0)  else    if (($arg0) & 0xF) == 0x3       etp-pid-1 ($arg0)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?