DOC PREVIEW
Berkeley COMPSCI 186 - Using ddd with postgres on the instructional computers

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Using ddd with postgres on the instructional computersCS186 StaffUniversity of California at BerkeleySeptember 6, 20051 AssumptionsFor the purp ose of this document I will assume that we are working with the postgres source tree that has beensetup for Pr oject 1. Please follow the instructions in Section 3 of the Project 1 document carefully. In Project 1you will have learn how to start the postmaster with pgctl and create a database with createdb. This documentwill assume the existence of a databa se called test. Using the test databas e , we perform the actions listed belowto create a table T, populate it with data (in this case we load it with 100000 rows) and then stop the postmasterwith pgctl stop. (These steps take time!).pentagon> cdpentagon> pg_ctl startpostmaster successfully startedpentagon> psql -f ~cs186/gendata/sql/tddl.sql testpsql:/home/ff/cs186/gendata/sql/tddl.sql:1: ERROR: table "t" does not existCREATECOPYpentagon> pg_ctl stopwaiting for postmaster to shut down...DEBUG: smart shutdown request....donepostmaster successfully shut downpentagon>2 Using dddThere are two ways to debug postgres :1. Interactive mode2. Bare backend modeThe interactive mo de is where you star t up the postmaster process (with pgctl), use psql to connect to it, whichspawns off a separate postgres process that is dedicated to serving requests from the psql client. This is the modethat the scripts in the Hw1/MyStuff/PerformanceEvaluationScripts directory us e, and the mode you used inHw0. In the second mode, you don’t create a separ ate postmaster process and don’t use psql at all. Instead, youstart up postgres from the command line and directly interact with it. While the latter is a very terse way ofusing postgres it has the advantage of being very debugger (like ddd) friendly.This document will restrict itself to showing how to use ddd with postgres in the bare ba ckend mode. If youreally rea lly want to use ddd with postgres in the server mode please talk to your TA for more help. This is notintended to be a replacement for ddd documentation. Think of it instead as a sample to guide you.1. First check to make sure ddd is in your path.pentagon> which ddd/usr/sww/bin/dddpentagon>If you can’t find ddd contact the course staff or your colleagues for help.2. Startup ddd with the newly compiled and installed version of postgres.pentagon> ddd bin/postgres &The ddd “splash screen” would have come up (albeit a little slowly) and a few dialog boxes will open up.Read them and click anything you find interesting if you want to explore. Otherwise click on “close” until themain ddd window comes up. This should loo k something like Figure 1.Figure 1: Initial ddd screenI prefer having the toolbar embedded in the source window. So I click on Edit->Preferences and modifythe dialog box as in Figure 2. There are other settings that you might want to change as well. Remember touse Edit->Save Options to save your settings!Figure 2: ddd preferences dialog box3. Now you are all set to sta rt examining functions. We will start by looking at the function GetFreeBuffer.Clear what’s in the topmost pane (it probably has main in it) and type GetFreeBuffer instead. Then clickon the Lookup button immediately to the right of this pane. This should look something like Figure 3.Figure 3: ddd after looking up GetFreeBufferFigure 4: ddd dialog box for postgres arguments4. At last we ar e all set to actually run postgres ! You can do this either by hitting F2 or by using the menuoption Program->Run. This will firs t result in a dialog box where you should type test. This will look likeFigure 4. Click on Run and your ddd screen will now look something like Figure 5. Note the backend promptin the third pane. This is the postgres pr ompt in the bare backend mode. This is different from the promptyou are familiar with when using psql.5. Next we place a breakpoint in the function GetFreeBuffer by clicking (middle pane) on the first line of c odein the function after the variable declarations. You can either right click and choose the set breakpoint orclick on the line and then click on the Break button (a little to the right of the Lookup button). Your dddshould now look something like Figure 6. You might have to hit enter to see the backend prompt again.6. Now click to the right of the backend prompt and enter select count(*) from T;. This will cause thebackend to run your query and stop at the breakpoint. In the middle pane you will see a green arrow pointingat the “stop” sign (the breakpoint). Now assume we’ve se t a breakpoint at the beginning of the functionStrategyBufferLookup, which is located in freelist.c. When the execution thread reaches this function,a trap will cause ddd to stop and your ddd screen will look something like Figure 7.7. At this point you are ready to rumble. You might want to try one or more of:• Look at the current state of your stack (Use Status->Backtrace) - something like Figure 8)• Display the local variables (Use Data->Display Local Variables or Alt-L) and display the arguments(Use Data->Display Arguments or Alt-U). The res ult should be something like Figure 9 after you stepthrough a few instructions.Figure 5: ddd running postgres in backend mode• Display any expression you see fit. Just use your mouse to highlight any expression on the code. Youwill see the expression show up in the top pane. Either click on the Display button (to the right of theBreak button) or right click on the highlighted expression and choose the appropriate option.That’s it ! You’re all set to go ahead. Play with ddd - a debugg er is useful for mor e than just finding errors.It’s also extremely useful in stepping through c ode that you might not be changing just to give you context. Thedisplays in ddd ar e extre mely useful for understanding data structures. Any time you see a pointer you can typicallydouble click on it and see the structure it points too. If it’s a vo id pointer and you know the actual type, you cantype cast it by right-clicking on the pointer in the data pane and choosing New Display->Other.Good luck and let us know if you have problems.Figure 6: ddd after placing a breakp oint in GetFreeBufferFigure 7: ddd after breaking in StrategyBufferLookupFigure 8: Examine the function call stack in dddFigure 9: ddd displaying loc al variables and


View Full Document

Berkeley COMPSCI 186 - Using ddd with postgres on the instructional computers

Documents in this Course
Load more
Download Using ddd with postgres on the instructional computers
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Using ddd with postgres on the instructional computers and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Using ddd with postgres on the instructional computers 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?