Changes between Initial Version and Version 1 of DevWikiGettingABackTrace


Ignore:
Timestamp:
Nov 17, 2009, 7:28:36 AM (14 years ago)
Author:
mcayland
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • DevWikiGettingABackTrace

    v1 v1  
     1= Background =
     2
     3Sometimes you may experience a bug in PostGIS and/or any of its dependent libraries which causes a crash when you try and execute a query. If this happens, changes are you will be asked to submit a backtrace to the mailing list. A backtrace gives an indication of the state of a program when it crashes, and is hence very useful for developers.
     4
     5= Prerequisites =
     6
     7This tutorial assumes that you are running a POSIX-based operating system such as Linux, Solaris, MacOS etc. If you are running Windows then you can obtain a similar result once you have installed the required MingW components. You will need to make sure that gdb (GNU debugger) has been installed on your system; to verify this, simply type "gdb -v" and check the output. If gdb is installed, you'll see something like this:
     8
     9{{{
     10GNU gdb 6.8-debian
     11Copyright (C) 2008 Free Software Foundation, Inc.
     12License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
     13This is free software: you are free to change and redistribute it.
     14There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
     15and "show warranty" for details.
     16This GDB was configured as "x86_64-linux-gnu".
     17}}}
     18
     19= Getting the backtrace =
     20
     21In order to obtain the backtrace, you'll need two terminal windows open. One to launch psql and connect to your PostGIS-enabled database as normal, and one to control the debugger. From here, the process to obtain a backtrace looks like this:
     22
     23 * call a PostGIS C library function to ensure that PostGIS is loaded in the PostgreSQL backend
     24 * find out the process number (pid) of the PostgreSQL backend you are connected to
     25 * connect the debugger to the PostgreSQL backend
     26 * execute your crashing query
     27 * obtain the backtrace
     28
     29
     30=== Window 1 - Launching PostgreSQL ===
     31
     32{{{
     33pg83@zeno:~/rel-8.3.7/lib/postgresql$ psql -d postgis
     34Welcome to psql 8.3.7, the PostgreSQL interactive terminal.
     35
     36Type:  \copyright for distribution terms
     37       \h for help with SQL commands
     38       \? for help with psql commands
     39       \g or terminate with semicolon to execute query
     40       \q to quit
     41
     42postgis=# select postgis_full_version(), pg_backend_pid();
     43                                  postgis_full_version                                  | pg_backend_pid
     44----------------------------------------------------------------------------------------+----------------
     45 POSTGIS="1.4.0SVN" GEOS="3.2.0-CAPI-1.6.0" PROJ="Rel. 4.6.1, 21 August 2008" USE_STATS |          29736
     46(1 row)
     47}}}
     48
     49Once you are connected to your database, you need to connect the debugger to the process listed above as pg_backend_pid by passing a "-p" parameter into gdb like this:
     50
     51=== Window 2 - Connecting the debugger to PostgreSQL/PostGIS ===
     52
     53{{{
     54pg83@zeno:~/src/postgis-svn/trunk$ gdb -p 29736
     55GNU gdb 6.8-debian
     56Copyright (C) 2008 Free Software Foundation, Inc.
     57License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
     58This is free software: you are free to change and redistribute it.
     59There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
     60and "show warranty" for details.
     61This GDB was configured as "x86_64-linux-gnu".
     62Attaching to process 29736
     63Reading symbols from /home/pg83/rel-8.3.7/bin/postgres...done.
     64Reading symbols from /lib/libcrypt.so.1...done.
     65Loaded symbols for /lib/libcrypt.so.1
     66Reading symbols from /lib/libdl.so.2...done.
     67Loaded symbols for /lib/libdl.so.2
     68Reading symbols from /lib/libm.so.6...done.
     69Loaded symbols for /lib/libm.so.6
     70Reading symbols from /lib/libc.so.6...done.
     71Loaded symbols for /lib/libc.so.6
     72Reading symbols from /lib/ld-linux-x86-64.so.2...done.
     73Loaded symbols for /lib64/ld-linux-x86-64.so.2
     74Reading symbols from /lib/libnss_files.so.2...done.
     75Loaded symbols for /lib/libnss_files.so.2
     76Reading symbols from /home/pg83/rel-8.3.7/lib/postgresql/plpgsql.so...done.
     77Loaded symbols for /home/pg83/rel-8.3.7/lib/postgresql/plpgsql.so
     78Reading symbols from /home/pg83/rel-8.3.7/lib/postgresql/postgis-1.4.so...done.
     79Loaded symbols for /home/pg83/rel-8.3.7/lib/postgresql/postgis-1.4.so
     80Reading symbols from /home/pg83/rel-8.3.7/lib/libgeos_c.so.1...done.
     81Loaded symbols for /home/pg83/rel-8.3.7/lib/libgeos_c.so.1
     82Reading symbols from /usr/local/lib/libproj.so.0...done.
     83Loaded symbols for /usr/local/lib/libproj.so.0
     84Reading symbols from /home/pg83/rel-8.3.7/lib/libgeos-3.2.0.so...done.
     85Loaded symbols for /home/pg83/rel/lib/libgeos-3.2.0.so
     86Reading symbols from /usr/lib/libstdc++.so.6...done.
     87Loaded symbols for /usr/lib/libstdc++.so.6
     88Reading symbols from /lib/libgcc_s.so.1...done.
     89Loaded symbols for /lib/libgcc_s.so.1
     900x00007f585979b305 in recv () from /lib/libc.so.6
     91(gdb)
     92}}}
     93
     94Initially, gdb will pause the PostgreSQL/PostGIS process when it connects. To unpause the process, type "cont" and hit enter:
     95
     96{{{
     97(gdb) cont
     98Continuing.
     99}}}
     100
     101
     102=== Window 1 - Execute your crashing query ===
     103
     104{{{
     105postgis=# select postgis_crash();
     106}}}
     107
     108When the crash occurs, this window will pause. You can then use gdb to obtain the backtrace using the "bt" command like this:
     109
     110
     111=== Window 2 - Obtain the backtrace ===
     112
     113{{{
     114Program received signal SIGSEGV, Segmentation fault.
     1150x00007f5859747ec1 in memcpy () from /lib/libc.so.6
     116(gdb) bt
     117#0  0x00007f5859747ec1 in memcpy () from /lib/libc.so.6
     118#1  0x00007f5857321621 in postgis_crash (fcinfo=0x7fff622f5f70) at lwgeom_functions_basic.c:114
     119#2  0x000000000058a7a9 in ExecMakeFunctionResult (fcache=0xc51310, econtext=0xc511e0, isNull=0xc518c0 "\177~\177\177\177\177\177\177\220��", isDone=0xc51978)
     120    at execQual.c:1351
     121#3  0x000000000058b0a4 in ExecEvalFunc (fcache=0xc51310, econtext=0xc511e0, isNull=0xc518c0 "\177~\177\177\177\177\177\177\220��", isDone=0xc51978) at execQual.c:1753
     122#4  0x0000000000591a72 in ExecTargetList (targetlist=0xc51750, econtext=0xc511e0, values=0xc518a0, isnull=0xc518c0 "\177~\177\177\177\177\177\177\220��",
     123    itemIsDone=0xc51978, isDone=0x7fff622f6494) at execQual.c:4610
     124#5  0x0000000000591f3a in ExecProject (projInfo=0xc518e0, isDone=0x7fff622f6494) at execQual.c:4811
     125#6  0x00000000005a200a in ExecResult (node=0xc510c8) at nodeResult.c:155
     126#7  0x0000000000587bc1 in ExecProcNode (node=0xc510c8) at execProcnode.c:319
     127#8  0x00000000005853af in ExecutePlan (estate=0xc50e98, planstate=0xc510c8, operation=CMD_SELECT, numberTuples=0, direction=ForwardScanDirection, dest=0xc07008)
     128    at execMain.c:1335
     129#9  0x0000000000583796 in ExecutorRun (queryDesc=0xbe9150, direction=ForwardScanDirection, count=0) at execMain.c:270
     130#10 0x000000000066022d in PortalRunSelect (portal=0xc08ba8, forward=1 '\001', count=0, dest=0xc07008) at pquery.c:943
     131#11 0x000000000065fe7d in PortalRun (portal=0xc08ba8, count=9223372036854775807, isTopLevel=1 '\001', dest=0xc07008, altdest=0xc07008, completionTag=0x7fff622f6890 "")
     132    at pquery.c:769
     133#12 0x000000000065a32e in exec_simple_query (query_string=0xbcb078 "select postgis_crash();") at postgres.c:1004
     134#13 0x000000000065e232 in PostgresMain (argc=4, argv=0xb360c0, username=0xb36080 "pg83") at postgres.c:3631
     135#14 0x000000000061f9f2 in BackendRun (port=0xb4bce0) at postmaster.c:3207
     136#15 0x000000000061efc2 in BackendStartup (port=0xb4bce0) at postmaster.c:2830
     137#16 0x000000000061cb35 in ServerLoop () at postmaster.c:1274
     138#17 0x000000000061c570 in PostmasterMain (argc=3, argv=0xb33310) at postmaster.c:1029
     139#18 0x00000000005b61ba in main (argc=3, argv=0xb33310) at main.c:188
     140(gdb)
     141}}}
     142
     143= Conclusion =
     144
     145The output from the "bt" command contains the information required by the PostGIS developers to determine the cause of the crash, so cut and paste this text unaltered into an email and send it to either the developer who requested the backtrace or the -users mailinglist if it isn't too large.