WWDC2004 Session 315

Transcript

Kind: captions Language: en good morning and welcome to debugging an Xcode what we'll cover this morning first we'll have a bit of a tour of debugging services in Xcode and then we'll talk about how to use custom data for matters a little bit of how you write the various formatters has anyone here actually customized any of the data for matters other than people that work at Apple well hopefully we'll increase that number after today is talk then we're going to talk about guard malloc and how you use that with Xcode and then we'll cover fix continued enhancements that are new in Xcode 1.5 and 2.0 in fact everything we're going to talk about today is in Xcode 1.5 and 2.0 and then we're going to do a little remote debugging we'll talk about the setup and show you what you can do with it and of course we have lots of demos for you so getting started the debugging service is an Xcode we have of course a graphical UI that graphical UI is shared by the Java debugger and our C code debugger that's C code debugger C based code debugger is gdb so when you're debugging your C code it acts as a GUI interface to GEB of course it has thread picker you can be your stack variables and also we have an expressions window you can also set and remove breakpoints right in your code right in the gutter there you can click on your breakpoint it'll remove it it's that one if there isn't one there already you can control click and get a little menu item so you can disable it if you want and of course you can control your program execution there are tool bar items for stepping starting restarting and of course their menu items which you can find your own key shortcuts do and of course it lets you access the cool features like fixing continue and remote debugging now our support for non sea-based languages include AppleScript and java which are not the topic of this talk so let's do a little tour now go to the demo machine and we'll show you what we have so first go up and up sketch it's launching a little slowly because we're booted off of one of those tiny firewire hard drives so one of the first things you'll probably want to do is to edit your executable in the executable inspector you can change the arguments that you're going to be passing to your executable so and also your environment variables so you can create sets of these and then toggle them on and off as you like however if you get too many it's a little difficult to manage large sets of them so you might want to go ahead and create a new executable item in your project and then you can have named it appropriately and then do bug it that way so let's start up the debugger here will click the debug button and we had our first breakpoint won't disable that here in the breaks point panel and continue so here's sketch running and we'll open up a document I've made before and go back in able our break point and now when I interact with the program we see that we hit the breakpoint in the debugger and up here above the stack and the column header is a little pop-up and it says thread one if there's more than one thread then the pop up will be active and you'll get you can switch between the other threads and then the stack will update the variables will update and your source will update to reflect that so you'll notice that some of these stack frames are grayed out and some are bold if they're bold that means we have symbols for them so that we can show you source lines and your variables that are in them if they're grayed out we don't have symbols but we'll go ahead and show you the disassembly down where the source view is so let's go back to the top of the stack and if you want to view the decembe li with your source go up here to the debug menu and you can toggle the disassembly display now in the seed you're going to need to click on the stack frame that you're looking at and then it'll update the PC pointer over in the disassembly view but here we have your source code and your dissembling in the same view and if we go up to the toolbar and we do step over instruction you'll see that the PC and the decembe lis is changing as we go through the code but those lines that we're stepping through are all on the same line of source if you do a step over you'll see that we've stepped over in the source view and then the PC and the disassembly is also updated now if you'll notice in the variable view we have variable graphics here it's an NS array and it's just been set as you can see from the source code where a breakpoint is whenever value changes between stepping will highlight it in red for you so it's easier to see if we step again you'll see the eyes changed and highlighted in red so now we can actually go and edit the value of I and we can set it to 4 and just to prove to you that it's set to 4 for those of you that don't like the gdb console you can avert your eyes now we can open the console for an eye and sure enough it's been set to 4 as you would expect but as you can see that's not going to be a good idea because we're going to iterate through our for loop there and we'd probably cause an exception as we access the array so we can drag the PC back and then execute that line of code again just another way we could have gone and edited that value and set it to three again but it's a useful technique to be able to move the PC if you've accidentally gone past Hawaiian of code that you want to step into say there's a function you wanted to step into and you've gone past it you can simply drag the PC back and then click step into so with graphics we see that it's in NS array and it's telling us that there are three objects but there isn't much more information there so what we can do is using the contextual menu we can print the description to the console the console automatically comes up for us and if we scroll up to the top where it displays the variable we see that NS arrays have a description where they'll give us the count and then tell us what the values are and then it'll go through each element of the array and do description on those and we see that the elements inside the array each have a very verbose description giving us the bounds the class in this case it's a circle and some other attributes now I like my gdb prompt to be a little bold so we can go to the debugger preferences and we can set the font size and we can change it to bold and click apply so you can go through and you can customize your standard in standard out you can have different fonts if you want different colors even and as you can see over here in the source code view I've actually changed the instruction pointer highlighting to a light green you may have been seeing red and all the other demos one other important item to keep in mind is that we have key bindings so if you don't like the the default key bindings for the various debugger functions the stepping that sort of thing you can define your own now let's go back to slides so as I click hmm one word so and you also see that when we're running in the debugger and if you were to quit Xcode we say nope we're running this also works for the run panel that's been much requested and that's fixed in Xcode 1.5 in 2.0 so let's go back to slides now custom data for matters we introduced them a year ago and how many of you know when you're looking at a custom data format or in the variable view of course the Apple guys so basically they'll let's you summarize the information so you don't have to turn down the variable for instance structures can get quite long you can summarize exactly what you want to see it saves a vertical space which is very precious on a lot of screens and you can add your own custom text to the data values let's go back and you can also evaluate expressions you can make calls to functions as part of your simple expression data for matters and you can also create custom plugins which can be more complex now custom data for matters they're bound to a type so if you change the variable formatter for one change the formatter for one variable it's going to change the formatter for all variables of that type just something to keep in mind we have about 35 carbon formatters for instance OS error FS ref and some structures and we have a bunch of about 35 foundation for matters as well for instance you saw NS array we tell you the count of objects in this dictionary we tell you the number of keys we have for matters for Anna's point and us rect some of the app kit structures now your user customizations are all stored in your home directory tillable library application support apple developer tools custom data views custom data view stop you list so if you have a great set that you want to share with other people you can give it to them they can paste they can then insert it in the same place in their home directory and then they'll have the same data for matters that you have and for plugin support you should look at the data format or plugin h file which is actually inside the Xcode app app wrapper you have to search down inside that probably with terminal or you can use open package contents and finder now summary formatters their lower overhead than the other four matters they're basically percolating values that we've already fetched or are easy to fetch into the summary the recursive so if you have one formatter for one structure that has another structure that also has a formatter then that formatter can be used as well and you don't have to drill all the way down into those children the basic format of a summary formatter is a child path surrounded in percent signs colon and then a referenced column now the child path is a dot delimited path to the child data value a lot like you would reference a structure in C and C++ child paths can leave out private protected in public you don't have to reference those we'll skip those automatically for you now the reference columns all refer to the columns in the variable view for instance there's the name variable column there's the value column the type and the summary column so this is going to reference which of those columns of the variable you want to display in your summary and we'll cover that in a little more detail so here's an example where we have an NS Point has two elements an x and a y and you might write a format it looks a little bit like this so you might have x equals percent X percent and y equals which is some custom text you can put anything there and then % y percent and it might look something like that in the variable display I'm a similar thing for Ananas size where you reference the width and the height surrounded by percent signs and some custom text before or after it and that would display something like this as we talked about before they're recursive so if you have an NS rect which has an Origin which has an NS point and then a size as two elements of that structure you can simply reference those elements and their data for matters will be used so you might have custom text parentheses surrounding a reference to the origin as well as the size and then it would look something like this in the variable display now expression for matters are a bit more complex they're higher overhead because you're actually asking gdb to go execute some code or do some logic for you usually you're executing a function and it can't have side effects since you're actually evaluating something in gdb so if your variable formatter had something like I plus plus in it then I will increment and if I have some variable in the stack it'll have changed so be careful what you do you might also be able to do something interesting with that and you should always cast your expression formatter to the correct type gdb can be a little unhappy if it doesn't know the type for the return value of the expression here you're calling so it's always safest to cast the proper type if you don't enter the type and the formatter doesn't work cast as the proper type and try again and avoid taking locks avoid anything that will take a lock avoid anything that might need a lock is just not a good idea to do that in your expressions now expression formatter will look something like this you'll have your expression surrounded by curly braces and then again we have that colon referenced column the dollar sign bar is used to reference your variable in the expression that you write now you want to think you can think of your expression for matter is though it we're variable of the type that you've cast it to in the variable display so if it's a char star char stars happen to show up always in the summary column so you get to an example of that in a minute so for an NS array if you've ever gone and double clicked on the summary column of an NS array you might have seen the format it looks sort of like this so we have some custom text we have curly braces surrounding our expression dollar sign bars replaced by the actual variable when it's passed to gdb for evaluation so we get back an integer which we're casting to be safe and we're casting were or including : V at the end just to be pedantic it's the default if you don't include any reference column then that's the default so just for correctness now you could do this type of formatter for a pool if you were tired of seeing ones and zeros for all your bowls you wanted to see true and false because that's what you're used to programming it has or you might want to see this yes and no if you're in cocoa so here again we have our custom expression and we're casting it to a char star and because we're casting it to a char star we need to reference the summary column so for an STL string for a standard template library string if you're you have a simple null-terminated string you can use the formatter like this to be able to view that string in the summary column so here we're simply calling have some custom text C string equals curly brace casting are expressed into a char star dollar sign bar dot c ng score STR function call close it up and end it with : s now for custom data format or plugins you can do more complex things basically allows you to do a custom print for a debugger on types that you may not have access to or somebody's giving you a framework and they don't have custom debugger printing it's automatically used so once you create one of these bundles in it is a Appy list that specifies which type it's for and Xcode will automatically use that data for matter for that type and this code runs in your program so you want to be careful what you're doing if you're not comfortable with allocating memory or being carefully just not over running the buffers that you're creating then you might want to be careful with these be sure to handle invalid input often times these variable formatters will be called before your variables have been initialized so you want to be safe with what you're doing now in order to create a custom data format or plugin you need to start with a new project we'll have a demo of this so you don't need to write it all down then you need to add a bundle target to it for instance a cocoa bundle and then you'll need to add a Heather search path in this case you can see that it crawls down into Xcode application app bundle itself that's where the data format or plugin dot H lives this way we can simply reference pound include data format or plug-in H in our code and then you also need to add a custom data format or views dot P list this is the P list I was talking about that specifies which type this custom data for matter is for and also what summary string to use so here we see dictionary with a key which is bool and that's the type that this formatter will be used for and then summary string is the next key and that's the summary string that will be used in the summary column so in this case we're cut we're calling my bulla description dollar sign bar going to be replaced with the actual variable dollar sign ID is used by Xcode to help the plug-in custom data views manage the allocation of memory so that we have because we don't know how long it's going to take for Xcode to go and fetch that data we can't use a single buffer for that so we need to keep track of that so that's something that'll be passed to a custom print function that we supply that you can use in your custom plugins here's some example code up top we see that we have a pointer to our PBX gdb plug-in functions those are the plugin functions that we support for you and we declare our function which is my bullet descriptor and we have our type which is bool and int for the identifier for that memory call now if you look at the code we see that if a bool is yes then we're going to construct this print function which is going to cons up the message for us allocate some memory and take care of managing that for us so we can return any string we want now we have Jim Ingham on to give us a demo of custom data for matters this one okay so we're gonna go over these kind of an order of dangerousness from not very dangerous to very dangerous open these so the ones that are the % ones that's really doing nothing that's just taking information that's already fetched on your behalf and and using it so I'll show you those that those you know you can play around with those for free they're really it's really nice you can go in and you know as you're looking at something you know change it for a little while change it back they're really easy once you get the syntax is straight forwards just like your C syntax and kind of once you get into the habit of just oh I want to see these two fields now oh I want to see these two fields now it really becomes an interactive thing that you can go and and do as you're going along it's it's really a nice workflow I think okay so let me find somewhere interesting that I want to be tt okay so we got sketch again that's what we're using as our example all the time this year okay so I'm here somewhere so I have this bounds which is got custom data for matters already you can see if you want to see what the custom data for matter is for anything remember you just double-click on it and it'll show you what the current data for matter is but maybe my what I like is to keep my value column fairly small because I have you know a lot of strings or something like that in the summary field I want to make that big so we chose to put this particular set of custom data for matters in the value column and that's annoying to me I don't want to do that so I want to move it over to the summary comb so that's that's what I'll show you how to do first so that's pretty straightforward let me actually do it for the constituent elements first so bounds has you know a point in a and a size so let's take this one and you can just copy it from here and double click and put it over there so now it's gonna show up over there so that's all you have to do it you know once you get used to this is something that's mine right you can really change in a nice way all the stuff that you view so I put this one over here right then now I've got redundant information so well maybe there's something else I'm interested in here like since it's a structure or maybe I want to see what the address of the structure is so that one would be pretty straightforward to do too that's going to be an expression because we didn't fetch the address of the structure in a way that you can get at it so but you just write an ordinary C expression surrounded by the curly brackets that's our little syntax which says this is an expression with send a gdb and I'm just getting you know the address of that array for some reason it's not updating right away but it'll update in a second don't worry and then maybe I'll do the same thing here because well I don't know but because I said so in the demo script okay so I've got that but then notice over here so this is the the deal with the columns that's a little bit confusing at first but it's actually pretty straightforward you know I changed the value contents of the origin structure that was contained within this bound structure so then all of a sudden what started showing up as the summary for origin in the bounds structure that contained origin is that address that I wrote in and the reason for that is because the summary here that I'm getting is coming from the value column by default because I haven't put a colon which column am i referencing in the origin right which is this one that I'm pulling the format or out from so if I want this to come now from the summary column because again I've moved the information I'm interested in from the value column to the origin column then I have to say that's from the summary column and the same thing here I have to say that's from the summary column so now that shows the contents from the summary column and which is the one I want it for the outer summary so again can move this over here and I don't know you know I could take this one and put it over here just to make everything look pretty so okay so that's the two things one you know double click to find them that's how you discover them the notion of you know when you have a substructure like this origin substructure you can use it in the parent just by referring to it and again the column says in the sub structure that I'm pulling values out from which column am i referencing like am i referencing the stuff that's here or am i referencing the stuff that's here in the formatter up here okay so that's pretty straightforward [Music] okay cool so now I don't want to stop here anymore yeah hey what do you want to select Aptos oh I see now I have source yay okay so the next thing I want to stop at is like I want to be in SKT e okay [Music] here you okay so here's another place like my document is a type that's mine and you know it's the one in sketch that contains the circles and squares and so on and so forth so I actually might want to see some useful pieces of information about it like in this case maybe what I want to see is how many circles do I have and how many squares do I have that might actually be a useful piece of information so it turns out that what the document contains is actually NS arrays and it contains an NS array of circles and contains an NS array of squares and then it has an access or method called rectangles to get the NS array so there's no way that I'm gonna find out those numbers by you know grubbing around instructors cuz NS array is hide from me where the number of elements is and my little accessors are such that you know I'm hidden where the NS array for rectangles is so I'm gonna have to call some code to do that but it's pretty straightforward access or code so it's really not too much worry it's unlikely that I'm gonna crash my program you know calling for circles or squares or change its state by getting the number or something like that so that's the kind of function call that you can call in to the inferior that's actually pretty safe it's it's not gonna do any harm on the other hand me trying to type while you're watching me do infinite harm so I'm not gonna do that I'm just gonna you it's not gonna let me copy are you gonna watch me type okay that's gonna be fun so for instance maybe I just want the number of circles here just to limit the your fun so you know I have to call to get the number that I'm gonna get the number of get the array and then get the number of elements in the array so the number of elements in the array is gonna be an int and here's my variable so dollar var that's the the thing that I'm referencing the document and I'm gonna have to get the circles out of that oh I have to get a curly brace on the outside yep so you really don't want me to type here and then now I've got the circle so that's great note I cast the yeah the outermost thing this one is going to come back as an in that's fine and then that so that's the circles that's an nsarray really but it's fine to call it Enid and I'll count on that yeah I probably do this is one of those you just keep typing until it works okay so yay that shows me circles and if you wanted to watch me type and that horribleness then I do the other one but I'm not going to I don't amuse myself that much so then the other example that oh yeah that's okay one of the thing to notice by the way so here in graphics the what we have is kind of this little grayed out version of the varial formatter but we don't have anything and the point for that is what Chris said namely that graphics is actually not initialized yet right graphics gets initialized in the next line of code that we're going to execute so but this is actually calling again a function it's calling count and something like that so in most cases you know gdb is actually probably what happened was that Xcode went and asked you to be to call this function and you know var contains some junk some you know whatever was on the stack at that point and that probably crashed because you know calling selector on some junk generally crashes but jeebies pretty good at cleaning up that sort of crash so as long as what goes on in the functions you call in the for matters don't change state it doesn't really matter too much if they actually don't go terribly well when you call them sometimes because gdb just wipes up the stack ago so I didn't see that and everything's fine so you don't have to worry too much what you have to worry about is stuff that might change State or stuff that might acquire resources because like if you have a multi-threaded program these are going to be running another thread might have the resource okay and that's the sort of thing that'll go badly but just like a little minor crash that really won't won't affect too much so okay we want to stop somewhere else I'll show you the bool example that that we showed before just so that you can see that it actually does work and that you're really calling you know any expression that's valid in your current language is what you're calling I want to be in you okay so let's go back here and run okay so here we're somewhere that has a pool and oh that looks really really ugly so let's let's make that look a little nicer so again we're gonna write an expression it's coming back as a char star and what we want is you know if the variable is one we're gonna return yes or yeah if it's positive we're gonna return yes and otherwise we're gonna return no so the only funky thing about this is that we had to put back slashes before the quotes and the reason for that is that this is has to be passed down to gdb and gdb has a command line which has certain syntax and one of the things is the quotes delimit arguments so if we past unprotected quotes then when that got down to GDB GDB would think that those were argument delimiters and the line wouldn't parse and they get all ticked off so anytime that you're passing a quote down just backslash it that's the only one that you have to worry about and again it's one of those you need to just keep typing it until it works kind of things that's why aren't you working hello all my typing just went away what did that happen Kris so dollar var maybe I know that's running [Music] oh yeah you're right I'll get it yeah yeah at that one isn't Titan on stage fun yeah well I typed something wrong I'm not gonna try to type it right on stage because I can't type but anyway that would show up the other one I wanted to show you just to just to make the point and this one I can type is pretty straightforward just to make the point that you you know you really are playing with power tools here is that you could do something like this okay that's a nice little expression and then you know three four five okay so you really are changing the state of your program so so you want to be careful about that okay so then the last thing that we want to do is show you how to do the plugins where you build your own custom plug-in and so as I say you know from the percent ones which are just information we've already fetched so there's no way you can screw it up to the curly braket ones which you're calling functions and it's getting a little more dangerous to the ones where you're actually injecting your own code into whatever program that you happen to run under the debugger where you know you're getting really dangerous but on the other hand if there's stuff that you can't get from the external level calling functions or something like that or if there's kind of a formatting that you need to do which it is time consuming or you know just a drubbing around and some more stuff than you want it right here I mean these can be valuable for instance the carbon stuff was done that way because you know you wanna like go and look through a window and pick out the ten things in the window list that are really interesting to you and format them up in some nice way I mean that's actually would be tedious to write in as an expression the summary of you you probably could write some really long thing that did it but you'd surely get it wrong writing it as the plug-in is easier so for that we have to go and make a new project so it's easiest just to make an empty one and I will call it and put it on the desktop so I can find it okay so what I want to make the the depending on you want to make a bundle because it's something that's gonna be loadable into your program but if for instance you're gonna be doing a another carbon data format or you'll want to make a carbon bundle cuz that it'll set it up so the link to carbon correctly and have all the stuff you need if you want to view some you know app kit types then you want to make a cocoa bundle what whatever you whatever the point of the of the formatter is so we're just gonna make it a cocoa one a cocoa loadable bundle and we'll call it okay so one of the things that we have to do as Chris said is we have to go and set in the header search path to point into this horrible location which I nicely put on this thing but anyway so you get to watch me type again that's roughly right we'll just find it out when it doesn't compile okay so you have to add that search path because that's where we stored this the the data plug in dot H file and then what you need is the P list file and you need the C file that actually implements your code so because I couldn't possibly type those here I have them already made okay you wake up a little firewire drive okay so here's the plist no that's this one yeah same thing that Chris showed you no work we could actually within a given plugin define for matters for a whole bunch of different types in this case we're only defining one for one type and then here's the the name of the function that we're defining so we're just in the same way you would do any variable format or what's happening is that this code gets inserted into the target program it provides a bunch of functions and then you use the normal variable syntax to call out those functions the one thing to be careful about of course is remember that you're gonna be inserting this into whatever code you happen to run in the debugger so you probably want to be a little careful about choosing some gnarly name you know like my bull description is probably not a good choice you know xx xx underscore some numbers and what I don't know but anyway choose something that you're not going to collide with other symbols and then the little ID token which is how we manage memory and resources for each instance of the running data formatter and then here's the actual code so again we provide some plugin functions in this case basically the ones that are useful are there's a sort of a printf but it printf to somewhere that we can find it and and there's a there's well this is just a print a string and then there's a there's an actual printf which takes all the printf arguments that you can use if you want to do more fancy printing and then there's one that help you handle memory allocation if you need to allocate memory because it's nice to let us do it rather than that rather than just cook on your own so we're not using those two we're just using the simple message which just prints a message it's good to check for this thing that's gonna be set by the the data format or code that Xcode always runs in the target program but maybe that didn't work for some reason or you deleted it and forgot or something like that and if this code ends up showing up that's not going to be defined and your crasher program and we probably won't recover at that point and then we're just taking the variable that's passed in so we you know we we we were passing in dollar var which was gonna be some bool so it's a bool when we check and print true or whatever print false so it's pretty straightforward so you can build that DDD yeah we're AB kit okay wonderful okay so then you have to find your build products which in our case are here here and move this into the proper place for where plugins go so where that is is in your home directory library application support apple developer tools custom data views so that's where the things should go this is by the way we're also the custom data plist that stores the ones that you've typed in like the percent ones and the VAR ones they're all actually stored in here so if you want to see what you've got or if you want to get rid of them all at once for some reason go into this same location just delete that file so that there okay well anyway that was the finder and I think you have to quit Xcode to get it to reread these it looked like it you didn't one time but it's a demo so I'm not going to try that so let me open the to one side here and go again I didn't open the other project opened oh look at that so there's not the desktop so what's going on here is just the breakpoint that I wanted to stop at was said in a framework not in the main app so you have to actually have the framework open for it to know that they're bringing there so let's see I put something there so it was overriding the default one again anything you type in at the console is gonna override any built-in ones but then when I deleted it it switched back to the default one which was calling my function and that printed false so pretty easy to do ok let's go back to slide I'll go back to slides now so thank you Jim now we have some new ways to display data in Xcode 1.5 and 2.0 we now display file statics right in the variable display so if there any file statics thank you there any file statics will display the file statics turn down if there are no file statics and it won't be there or if we can't detect any of the symbols so it's just like the arguments and the locals if there are no arguments or locals and those turndowns don't show up in the variable display so we also have the global variables browser which was shown on Monday lets you browse global variables by library you simply go into the debug menu the tools and bring up the global variables browser inside that browser you can then search and filter on the various fields multiple selection doesn't work yet we're working on that and then you can click in the view column for the items they actually want to view in the variable display so it's a good way of filtering down from possibly hundreds or thousands of global variables that could be in your programs space down to just the ones you're interested in we also have the memory Brown simple memory browser and you can either type in addresses you can type in variables you can also type in some expressions which Jim will probably show us so let's get Jim back up here for file statics and global memory let's have this one again okay so in this case you know of course we're a nice object-oriented application so of course we have no Global's and almost no statics so actually constructing the demo is a little bit hard because there really wasn't much interesting but in any case I can find some place so let's see find the same place that I was before okay so we'll run you know well we stopped there instead that's okay so if you want to see well this one doesn't have any statics but if you want to see Global's again there's nothing here right now but we can make there be something to go to tools' global variables so there's going to be the list of all the stuff that's here the by Global's we mean global variables that have debug information because if it doesn't have debug information we don't know how to print it for you and so we're just not going to list it it turns out that app kit has a whole bunch of them and you can do evil things that you shouldn't do so I didn't actually show you that the the one thing other thing that that can be kind of confusing is sketch actually has a whole bunch of modules and we're building this with zero link so the way that zero link works is that each of the dot o files each of the modules in your program comes in as a separate bundle and they come in on demand that's the wonderful thing about zero link is you don't load everything right startup but you load it onto manage you need it but it means that in the global variables view stuff is not going to show up until it's actually shown up in your program because before it is been loaded we don't know anything about it we don't know where it's gonna live you know so so for instance here you know I would expect lots of SKT stuff and I actually don't have much but any case of what I have you know here's something so the way that you decide that this is something you're gonna view is you just click check that you're gonna view it and then you can close the browser and then it will show up under here so that's how you selectively view global variables without being overwhelmed by the you know huge number like there were 500 in app kit you just you didn't want to see those 500 so this is a nice interface for showing you that just to convince you that the zero link thing works the way that I said let's take that away ok so now I can go up and go back to sketch and I can turn on say the grid and I can you know I don't know change the spacing or whatever and then if I go back here and pause and now view the global variables again so now some grid stuff is shown up so this is what's gonna happen so if you want to view Global's your before you can discover them the first time you're gonna actually have to make that code show up in your program and then you'll be able to poke around and set it to be shown so that's that yeah and then statics just show up under statics this is a I can hit the other breakpoint and then I can find statics for you like so this one actually has some some statics they're just listed under the file static so these are the ones that are defined statics to the file and they'll just show up all automatically you don't need to pick them or anything like that that's that and then the third new thing that I was gonna show was that we now have a little memory browser so a memory browser it'll view memory at whatever address so for instance like dollar r3 here you could type in addresses you can type in you know any expression dollar are three normally stores the the object but yeah I don't know probably an object I can't really tell the other thing you can do is you know if you have accessors which are pulling out stuff and you want to see the stuff at the access or like for instance you know we pull out the document here by this self draw a document so we could just say self draw a document and it's going to resolve it to whatever the address is and then printed that it doesn't stay live it resolves it to the address and then it prints the address so if you wanted you know to track a location as it changed you'd need to reenter the expression every time the other thing is you know you can change how much you want to display you know bigger or smaller this is a little stepper so you can step through pages of memory based on the size that you have that's pretty much that okay all right let's go back to slides please so new in the debug menu we've had to reorganize it a little bit we have some more menu items for you and we wanted to still be able to fit on a 10 by 7 screen so as we had before we still have stopped on C++ catch and throw you can control the decembe lis display they're actually three modes there whenever in the default mode if you click on a stack frame with source will just show the source and then you can do the mixed view as we showed you earlier the third mode is that will show you only the disassembly whenever you are clicked on the frame that has symbols so if you want to stay in assembly mode or you don't want to split your screen then you can choose that mode and then you choose the mode a fourth time you dissin choose that menu item a fourth time and then that would get you back to the original mode and that's specified by a check mark and then a dash next to the menu item to show you what state you're in now you can enable and disable the data for matters either using the contextual menu in the variable view or in the debug menu under we have the same contextual menu that shows up in the variable view in the debug menu and you can select it there now if you're in the middle of debugging your program and you disabled the data for matters you can re-enable them later if they're disabled when your program starts then won't have loaded our introspection library and you only get the summary for matters whenever you enable the data for matters again just something to keep in mind we also have stopped on debug string call and debugger call right in the debug menu so you don't have to go to the executable inspector and switch it on there it is still available there and we track the two and keep them in sync and now you can enable Guard Malik right in the debug menu all these settings are now stored per executable some of those settings used to be stored per session of Xcode so if you had two projects open and you enabled break on stop on c++ throw then it would be enabled for all of your programs so let's talk about guard Malik a little bit what is it basically causes your program to crash and that's a feature what's detecting is it's detecting memory access exceptions beyond your allocated buffers it can also detect access of freed buffers and this is all done because at runtime we insert a debug version of the Malik library at runtime as your load as your program is loading up in the debugger and then it uses the VM system to add guard pages around your memory allocations now it also overwrites freed memory so that you can with bit pattern so you can detect when you've read that memory in a little bit of an assistant there however your codes going to run a little bit slower because it's doing extra memory allocations in order to put guard pages around the allocations you've done in fact it pushes your allocations so that they end right at the end of a page so there maybe there's could be potentially more memory being allocated than what you've asked for however it's still thread safe which is good because a lot of applications you're writing today have other threads getting launched for them either via app kit or carbon so how do you use garden malloc well it's best to use it with the debugger because it's going to cause your program to crash on these memory access exceptions so then that'll give you the back-trace that you can then go use to find out what the problem is as we said earlier you enable it in the debug menu and this is essentially causing us to environment variables the first is D while D insert libraries and then we specified the Liberty malloc library and that will cause Lib do malloc library to be inserted at runtime the second is force flat namespaces if your program will not run with flat namespaces then you won't be able to use card malloc again the debug is normal exercise your program and then we'll bus error throw up an exception we'll catch it on your bad memory access and then you can just follow the stack right to the problem so Garden Malik has a lot more options you can put guards against buffer underruns you can allow allocations over 100 megabytes and you can check for do extra checking before free and reality all you can also fill allocations with bit patterns so you can tell which memory you've filled up and you've allocated and then you can detect if you've read it by accident and there more options in the Lib G Malik man page these options are all environment variables which you can then go set using the executable inspector and set the environment variables like I showed you in the first demo and now let's get Jim back up here real quick before Garden Malik demo so again this one so I'm not gonna show you anything particularly interesting just to show you that it works and how you turn it on and stuff you know this is the classic mistake I made a buffer to hold a string but I forgot to allocate the space for the null right and then I wrote some stuff into it and and overrode it so if you do this and and you just run it then I mean it just runs fine it nothing happened right there was no mistake but there actually was a mistake which as your program got more and more complicated you would eventually come across so what's better is to run under guard malloc when you're worried about I have some weird behavior or maybe it happened upstream I don't know where but I can catch it and again that's easy to do that's just a menu pick enable guard malloc if you want some of the fancy options you need to go into the executables tab and set environment variables as Chris said but we're not going to need to do that here all we need to do is just debug it so we get a bad access right when we did the store copy which is what you expect because we went one character past the end of the buffer we allocated to write the null which we hadn't allocated and it just gets us right away so that weird zero which ended up showing up in some other data structure somewhere you can't figure out why you figure why immediately so that's what garden malloc is for let's go back to slides go back to thanks Jim so with VIX continue which you're into which we introduced a year ago allows you to change your code while you're debugging your application you can make the changes while you're running the application and you can't in you can continue your debug application to continue your debug session without having to do a recompile in real ink so it allows for more of a prototype style development it's extremely useful for those long debugging sessions whenever you're have a bunch of program States set up and you want to do some simple changes try and fix your program however requires that you use native targets which is the default for most new targets that you create in Xcode and of course it requires GCC 3.3 now new and xcode 1.5 and 2.0 we have support for fixing and supporting projects so if your application is in one project and you have supporting frameworks and other projects you can now fix the code in those frameworks while you're debugging your application this requires that all of your projects need to be built with debugging symbols enabled so probably just the development build style fix continue needs to be enabled and if you're using C++ you need to enable zero link as well now all these projects need to be open the next code at the same time so we can go find which target has the file that you're trying to fix so what can you fix you can change logic you can add new calls you can delete code you can change constants and some other constant some other common operations things that won't work you can't change the size of structures or class layouts or function signatures can add global and static data and if you happen to be trying to fix the frame that's at the top of the stack you can't add local data and if you do make changes that require initialization then you need to be after you do the fix you need to make sure to move the PC back to execute the line of code to initialize your data let's get Jason up here for our fix continued thanks Christopher so can we get the demo machine up please thank you we're gonna be looking at the sketch project again because it's our favorite project of all we Christopher is splitted into two parts of framework and an application so that we can show the support for the supporting projects and fix the continue that's new in this release unfortunately it's not actually working in the tiger seed but we're gonna have it fixed by the end so just bear with us for now but it's going to be in the final tiger so here on the you see on the screen we have the framework project right here and we have the application project both of them built already so we're gonna launch them in the debugger and the little hard drive spins here we go so the basic thing we get a circle it's filled with blue probably not what we actually intended so this is a great chance to use fix and continue to change the behavior of the program without having to restart it and relink it and recompile and all that other stuff that you have to do normally so the thing that we're gonna fix is over in the framework so over here we're looking for SKT rectangle which has the rectangle class here it is and we have the setup function right here so let's set a breakpoint there and let's draw another circle swear rectangle here we have a chance to change the color that's using for the fill right now it's setting blue let's change that to red because maybe that's what we actually intended because red rectangles are what everybody needs more of now we're gonna say save it and fix compiles the file link succeed and fixed now if I continued at this point as you can see the PC has already passed the point where it sets the color so even though we fixed it the colors already been set we need to move the PC back a couple of lines so it's going to set it to the new color if we drew another rectangle after this and we get the new color but we want it on this rectangle so let's drag the PC back up to where it's setting red color and then continue from there unfortunately draw a really small rectangle it's just disable that breakpoint for a second there would be a red rectangle if it worked now we have red it's fixed and continued just like you've always seen it but you'll notice that the application which we're debugging is separate in a separate project from the framework or fix it continuing so the supporting project is the really exciting new thing here one caveat that's important to understand is that a file can belong to multiple targets so what you have to do if you have a pic if you're fixing continuing a file that's in multiple targets as a supporting project you're gonna have to give Xcode a little hint as to which target it is you're fixing so for instance let's do this again over in the framework let's duplicate the target so we have two targets with all the same files in them duplicate it and we'll just call a separate name so that it's clear now we have two frameworks with the same file in it again we're gonna well we won't stop at the breakpoint we can fix and continue without getting to the breakpoint in fact it has fewer limitations fixed continue when you stopped in the middle of function has a number of limitations on changing that particular function so instead let's just run in the main event loop and do the fix from there so instead of red color I think green color would be a much better color save it now when we try to fix it which we'll do from the debugger so there okay fix now we get this pop-up and this pop-up is telling us is asking us which target it is we're trying to fix so that it knows how to process it and get it back into the executable so we tell it that is sketchy framework build succeeded it's fixed now we get the green one one really nice feature is that once you've told it which target is it's going to cache that and remember it in the project so now if you do a different color we fix it again it remembered that we're working with scratch sketch framework so you'll only have to actually do the selection once and from then on it's just the default and we get a brown one so that's the new fix of continuous supporting projects Thank You Christopher Thanks in the back slides so now whether it be across your cubicle or maybe just down the hall we bring you remote debugging this is great for debugging those full screen applications games screen savers in fact some games if we know have had bugs in full screen mode only and so the only way they've been able to debug these is to go to the terminal on another machine SSH in and fire up gdb so they don't have the advantage of the graph above the bugger it's also great for debugging event handling so you're trying to drag the mouse and you want a debug at the same time now what happens normally is Xcode is going to have to come up if you've hit a breakpoint and now you aren't going to be able to move the mouse anymore in your program so with remote debugging you can now continue to use the mouse as you debug your application and it supports nearly all the xcode all Bex codes features and your seed doesn't support fix continue but should be pretty easy to fix for now one thing you won't be able to do is you won't be able to send standard into your remote process so you won't be using this to debug your command line applications remotely on another machine there's a little bit of setup for remote debugging you need two machines of course and remote login SSH SSH login needs to be enabled on the remote machine now I need to share the build products especially if you've built with zero link that's because these are links looking for the other datos that it's created at a specific path so if you're using a network home directory that's quite easy all both machines will have access to the build products with the same path if you use an AFP to share from one machine to the other then you might have to use symbolic links in order to fix up the path so that it's the same access on both machines note that finder aliases won't work currently so you'll need to use symbolic links to enable remote debugging you bring up the executable inspector you check the debug executable remotely with SSH and then you fill in the host text field with the username on the remote machine that you're going to log in as and either an IP address or a host name I need to make sure that the user that you're logged in as is the same user that's logged in at that machine otherwise you won't have permission to write to the Windows server and your graphical application will not watch so we're using ssh public key authentication this means that you need to set up your public and private keys on the remote machine xcode is SSH asian to wear so you can encrypt your private key and it's not a big hassle to and your passphrase once and then you don't need to enter it again until you quit Xcode or reboot the machine there's some documentation on how to set all of this up because we don't expect you to pick it up the first time and run through it vector not going to run through the whole setup here and that documentation is called remote debugging with Xcode and that's a connect apple.com reference library and tools now let's bring up gem for a quick demo of remote debugging quick because we're running out of time so let's let's start over here so we have one already set up let me just open up the application and the framework that goes along with it so this machine is another g5 this is the one we're working on here and we just want to debug I'm gonna sit okay so the first thing you have to see is this is the the sketch tab that's the main project and I need to make sure that the current executable is set up for remote debugging that's what I have to do on the on the host machine side so there's that nice little edit active executable you can get up to here you know look in the debugging tab so you check this checkbox debug executable remotely via SSH you have to type in the host and username and and IP address of the host and that's all I have to get that right you had to set up the SSH I'm not going to show you that because that would involve typing and you saw how that worked last time so we're not going to do that okay but then once that set up then it's just a matter of debugging so it's gonna ask me for my SSH password because I don't have an SSH agent running and I don't have any of the freeware that does ssh and passes it down to applications or shareware but it'll only ask me once once i've typed it in if i bugged again it wouldn't ask me again because it sets up an ssh agent itself and then uses that agent for the rest of the session a little bit can you switch to this machine for just one second so just to prove to you that it is here it's running it's running under the debugger you can you know do whatever sit and that's interesting okay hit breakpoints over here so let's go back to this this one for a second so see I I hit some nice breakpoint now I'm here I can step around or whatever the one thing that we saw here was you know what I wanted to do was I was stroking out a rectangle and and and I wanted to actually get away from you know watch the mouse events as I was stroking out the rectangle over here but one of the things that's kind of inconvenient is you know okay so I click down and and then it was great I stopped immediately at the mouse up event here which is what you see the event is is Mouse down mouse down event rather but now you know this mouse I've got to like you know put a sock full of rice on the mouse to hold the mouse button down and then slowly move it and then take the sock off for the mouse button up or whatever there's actually some one thing that's really neat that you can use in the universal access stuff which can make this kind of event level remote debugging which is that's where remote debugging if you're full-screen games and then for regular applications just like you know I have a tracking loop and I wanted to bug through a tracking loop you know how do I do that then there's one thing that I want to show you that will make that more convenient so let's go back over here continuous I'm not here anymore okay so what you can do is if you go to universal access in System Preferences and turn on the mouse keys feature the universal access in the mouse mouse keys so turn that on and then what that does is that makes the keys into the mouse movement but one of the really cool things is that it has separate keys for the mouse down not mouse click but just mouse down that's the zero key and then the five key is the mouse up and then the arrow keys of the movement keys so if we switch back over to this machine we didn't ever go here okay so I hit Mouse down here and see I broke in the mouse down and then if I continue and then I can click and get the mouse move and you know continue and keep getting the mouse move and I can go and I can you know have both hands and I don't have to worry about putting another mouse button and then eventually you know when I get to the point where I want to make the rectangle I have to continue of course and I can finally click the five and that's when I get the mouse up so that's that that'll you know free your hands and you don't have to get your child to come and hold the mouse down or whatever the one other thing that's that's here by the way the this was not one that we added I mean the event is an NS event and as we were going along it was really convenient I wanted to see what type of nth I was getting because I was you know making events over here and then looking at them over here so again we just added a custom data format or it turns out that under the event one of the member elements is is the underscore type that has the the type of the event and I was annoyed at having to turn that out so I just put it up there so that's just again the data format it's a really close like I want to see that now okay that's good [Applause] thanks Jim so now we need to finish things up so we can take some of your questions really quick this is the reference library there's remote debugging and Xcode which talked about earlier there's a document on fix continued there's debugging with gdb which is more in-depth gdb command line commands and of course we have Xcode help which is built right into the application it's a great resource to go look at encourage you to do that and now who to contact Matthew Formica you