DevTools hacking: Let's make it Build & Run!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
well hello friends and welcome back to dev tools hacking today I think I'm gonna try to make hack studio build and run something so we're gonna start by making like a really trivial project just to use as our testing project because last time I've been using like the whole serenity project and it's a little bit chunky for what I want to do right now so I'm just gonna make like a little little project look a little how about that and let's make a file here and how about we just do something really simple why not hello friend come on no come on let's say no comment okay and I don't want to see those warnings so I'm just gonna actually silly aims gonna do this stuff okay so the object of this video is to get to a place where we can build this project so the project format is just a list of the files and I guess we could actually have a make file of this vault so we'll make a little make file mm oops I'll pack my pacing [Music] and I guess we can just do that and then what is a percent Oh depends on their sexy PPE and all we have to do for those is I don't I don't write make files I'm scratch all the time so I'm a little bit rusty on this so - OH - the target compiled the first dependency and I guess this is where we would pass to see XX flags if we have some so okay remember this is for the past 2 lb flags but yeah let's not worry too much about that but we'll do a clean target as well mmm the struggle okay all right I'm just in program all right so clean okay so that's working Holly all nicely so let's switch to using this as our project AK studio main so where do they open the project again right at the top here home and on serenity so we're just gonna switched at home and on little open little dot files and let's see how this looks if we start it up okay so now we are in this directory and these are the files that we have it's pretty good so my thinking here is that this isn't supposed to be like a regular terminal is just a general approach terminal the idea here is to have a dedicated terminal where if you build a program and you run it then it will run in this terminal and you can interact with it as if it's running in any other terminal but it's not meant to be like a general purpose terminal maybe that's something that would be useful to have as well I don't know we can figure that out but at least then that would be maybe a separate thing from this because I definitely want it like a dedicated application console think so so far so good let's or you know this actually makes me think that it would be nice if I could see which file is open somehow because right now it doesn't show like I could select but it's only double-clicking that switches the file so how about we make it bold for the currently selected one so how do we do that let's see if gene list view notes had to render something in bold first of all so when you paint a list view we iterate through all of the rows and then the font for each row is the column metadata font okay so we can override the font that's good so it's overwrite it with a bold font if we are hovering the currently selected file orthe currently open file so let's see how did we do this again when we open a file then if we go here right so we double click on the file in the list and that just means that we open up the file and read the whole thing and then set the text editor of contents to that obviously we're gonna do something more sophisticated here eventually but this is how it works we just slurp in the whole file and then slap it into the text editor widget so when we do that we can also we can tell what do you want to do we want to store that name somewhere so that we can compare against it we will save it in a global is not the most nicest project list view model but maybe a global is the best thing we can have right now it's a little bit ugly but we're gonna need some kind of state where would this thing come from cuz I'm thinking we're gonna allow you to have multiple files open well you will only see one at a time right okay let's not think too much about the architecture of this right now and just make it work the architecture will come into place later as we go so the name of the file is filing right so open and string rename that immediately to G underscore just so that I remember that it's do I have to do that to make that warning go away I don't care about that warning was a stupid one is that a client ID missing variable declarations hmm well I mean don't worry about that one so let's see and this would be in project CPP um for the project model we have to override the column metadata so that we can provide our own font alright alright so that's extern and then what we want to do is wait wait hold on this isn't that all what I want to do this is the yes this would alright it for the whole column I wanted to override it for an individual row so I'm barking up the wrong tree here let's go look at the list view again so we get the font from the column metadata well I don't really want to do it that way can I get the font from that individual you know there's no way to encode a font in Ag variant at the moment so let's fix that right quick G variant okay I guess we can't just include it it's not a big deal so d variant is the class that we use to box various types so you can have a G variant which internally contains any of these things here and now it can also contain a plot because it will be useful if we want to return it font for a specific index into a model and then what we're gonna do is we're gonna write what the heck am i doing I have to actually look at what I'm doing here so G variants internally is this thing it's like a union of all these different value types so we do now is we just added another long and also add and aunt can I do it that way does that work cause I'm as fond this is only gonna work if it is indeed a font otherwise will assert in value as font okay then we just have to go and make that constructor overload take a taunt stop detective font as fog is tell you oh I must cast so font is reference counted so we have to take care of that here so it's pretty straightforward I cannot do that because I have to do that right maybe this is a little fattier actually yeah potato tomato right then we also have to care about the copy constructor it's a variant copy constructor is a little bit awkward you could probably do this with virtual instead but I am I've been doing it in this way for now but it's starting to become a little bit irritating to add stuff to it move constructor a so just see if you can fix it as fond I don't think we can't compare two formats County mmm there's no meaningful comparison operator for fonts so we'll just compare them by pointer no it's better than nothing or actually we assert here and we should have served for that too we could do it we could let it assert their how do we stringify this as font name it's good enough for me Oh or maybe actually something like like that okay surprised that I didn't find a move constructor though where the heck is the move constructor maybe the move constructor just is mr. Arthur is deleted but this one works fix me move in a copy okay so there's a fix me too to implement moving I guess it would be kind of easy since um all of internal types the complex types are all pointers so you could just you know move from one and then a lot are you moving from but we don't have to care about that right now let's just see if we can deal with this and then what I wanted to do was override the font so we're gonna need a new G model role for that so we'll just say font and here in the ListView or actually let me do it in the project model first so when you're asking for data from a project model then currently we only care about the display role then we give you the file name we could also say if role is role aunt turned oh and this is part of that global comes in so what the heck was is the name external string G any open file in files so if the current thing is the same s currently over five then we will return a default old font otherwise we will turn an empty variant and in this case we'll just fall back to the whatever the whatever the view wants to use it's just that yeah I think this would make sense and then the way we will use it here in the list view is that we reach our text let's see so this is where we extract the font so first we ask to call them metadata if it has a font if so we respect that probably I should make this go away but right now I'm just gonna leave it because I know that other other programs on the system are using it so I don't want to make it go away completely mmm so let's see mmm this is kind of awkward I'm thinking like should I separate it out into a function maybe font we can do fought for index something like that okay in the past what is the index called index oh but it's constructed down here actually so we can do that did you use any other part of the column metadata yes here text alignment okay but the font we can do differently so I was thinking font for index we'll put that in a superclass of G ListView so G ListView inherits from abstract view and then all the different views like table view item you tree you a ListView they all inherit from abstract views so we can put this here the font for indexed thing and then they can all use that which will make it easier to bring this functionality through the other views when I do that but I'm not gonna get super care to wait with this and go do that now but it'll be there it'll be nice to have so close font index and oh and we actually have to go fetch the column metadata but we can do that easily here so column data is this model to go for index column okay and then let's see if column metadata the column in it that it should be the fallback I guess because if we have a specific one exactly for this index we should check that first yeah is gonna take up is well data but if there is no mod returned default font but then we have a model so we'll say roll lots of data is fond return of data as fought look at that although this will be quite awkward because this will give you a Coast reference to an object that will go away so we shouldn't maybe I shouldn't be like that we'll fix that but if we don't have one we'll look at the column of the data and then we can say if column metadata has a font otherwise we will return the widgets font the geology would just have a font so that's what we'll give back so actually this is what we should get back here to not the default front but the widgets font um but this one is a bit tricky though because yeah we can't we can't go handing out a reference to this phone here I was thinking like someone else would keep it alive but there's no guarantee like this this call could generate a new font object and we have to make sure that it stays alive so we can't write the code this way so I guess we'll have to do it I'll have to give you a non-null back there too a thought yeah that'll be it because we're not gonna give you a it's never gonna be null like there's always gonna be some font that you get back so it's a nominal pointer and its reference counted so this is the right pointer type okay and then in a list you will get the font out we do it this way for index and I checked we got a little sidetracked with this showing it in bold and we're gonna get back to running the thing very soon so so if the role is fond then oh right right right so we want to G variant you bundle this is okay for it to do that and the G variant reference counts internally so this is actually okay because right so G variant reference a bumps the reference count on the font it's all good and then the only problem was that when we were retrieving the G variant in G abstract view here we have to make sure that the font we keep retaining the font it will keep reference counting the font which we will now because we return it wrapped in a nominal refer so I think the problem should be gone so I have some mistake down here right maybe we could actually do something more fun with the string of the currently open file I was thinking we could put it in the window title as well cuz why not studio okay now let's try it out look at that it changes the becomes bold but it needs to repaint after we change it because it there's no way for the widget to know that the model would give you a different font now so we have to actually explicitly say hey hey we need to repaint this widget after this happens so we'll just do that here we'll say yeah project list here very nice that's awesome okay so let's make some commits here hold on if we can do G variant by itself actually do we make it possible to wrap a hunt in Ag there okay the fact that I change about gene model phone type okay so there's synergy model for old G ListView will now use phones for index right and then we'll make use of that in hex to do to return a bold font for the currently open file right Wow over writing prompt on an 800 index basis in G this clear this should be ported to all of abstract view subclasses and then here this is just acts of your changes to show that currently open file involved we're also renaming the default project a little which I guess is okay actually let's let's add it while we just commit everything here it's not a big deal next to do currently open file and old project also import any tiny me a little default c-plus most project okay so now let's go back to what we wanted to do which is to try to build so I'm thinking let's just make a build action mm-hmm what's good for that control be I guess so we'll make a menu how about call it build nose is so itchy good thank you did I say control B I'm not sure that's the perfect one but let's just go with that for now and here we are going to build so I just put it in a function called build for now okay and what's that going to do I'm what we gonna do is build well that's and I'll start by just running a make command in the terminal wrapper thingy that we have so here we have this maybe we'll pass it to build terminal wrapper something like that I think that might be reasonable and then this will be like terminal to use or whatever and then what we want to do is run a command in here so terminal wrapper currently it has like a run command and it just does this so can run an arbitrary command although it's not a member function or anything we just start a shell one of the things starts up what we could fix that we could could turn it into a member function little command something like that are you reasonable and we will let it take care of this suit of terminal allocation internally instead let's see how do we do that oh right right right so currently we passed the Serta terminal to the terminal widget where we constructed so I guess what we want to do is actually make it possible to change the PT lie um so the terminal master in this case that's what BTM stands for so pseudo terminals are kind of interesting actually the way that it works is you open up this file and it's a magical file that gives you back sooner terminal but you don't always get the same file back like it will allocate a pair of pseudo terminals so I'll show you how that works in the kernel because it's kind of interesting so device that you're opening it's represented by this p2y multiplexer in the kernel this is basically the same mechanism on on linux and and other POSIX systems I think so you open this thing and you end up here and what happens is that we have a free list of indices so basically like / - / BTS / number is a suitor terminal index so we instantiate a new one with a free index I think we have some max number of these eight as the current max number in strategy and for every master PTY there's also a slave PTY which should be allocated by the master yeah you can see here when you construct a master it creates a slave as well and the master is them there are two sides of Ceuta terminals right if you're not familiar master is what like the controlling program uses so like if you're like an ex terminal for instance or a serenity terminal then you're the terminal application itself talks to the master bt lot and they're shallow that's for being inside of the terminal box to the slave and the slave is like internally linked with the master inside the kernel and the master learns what the slave is doing through this connection so that's basically what this does so here we are allocating a pair of pseudo terminals and a Stern's layer by opening this file it's kind of cool and then you call pts name on the file descriptor and that tells you the file name of the slave and then you can go and open that up and now you have this file descriptor is the master and then this file descriptor that you opened with this file name it's asleep anyways that was the fastest in terms of pseudo terminals that I could do so we want to be able to swap the city terminal in the terminal widget because because that would just be a useful thing to be able to do so let's allow you to have a terminal digit with no tsuita terminal it's not a separate constructor for that or actually let's just not have a separate constructor it will just let you say minus one so let's see PT MFD hmm oh right so the way that we handle everything here is I'm just seeing what the terminal widget does with the master terminal file descriptor so he tries to write to it in various ways when you press the key word mm-hmm or when you mouse down when you resize I try to IO cuddled to change the size okay so let's just do something like this and we'll say - one is the magic number that means you don't have a haplit then we'll say set so you know eg my master will do that in there so if you set - one well I'll tell you what this is in a moment so then the notifier is a magical object that will it will fire a callback whenever there is something that we can read from this file descriptor and you will see it and further down you can see here is where we set up a hook for it so I'm gonna move that actually up here and let me make this symmetrical okay so actually let me make it nicer okay so um notifier is a magical sea object that will fire this callback whenever there is something to read from a certain file descriptor that's why we say what we say here we can also say I'm saying if I write and then we will get a callback when it's ready to write it's very useful but in our case we only care when there's something to read from the master because it means that there are some something happening on the slave PTY so um like some output coming from a command for instance so let me add this API okay this is a kind of a Koosh but it's gonna be okay and then here in the key event will say like if there's no a Spectre open we'll just I bend and was our parent keyframe you know 1x yep key down okay then there was also Mouse down I think yeah Mouse down so if you click somewhere with the right mouse button [Music] we're not going to try to paste so say if I'm a PTM FD this one all right so let me construct it now we're going to pass in minus one as the file descriptor and then run command when that happens we're actually gonna actually going to give it a PT y so here we'll say M terminology set PT y master file descriptor feet and 15 this will fall apart like if you try to sequence commands now because it's not gonna like close the old one and everything but we just need to get started so I need to do we need to take off my hoody because it's getting a bit warm in here okay so I forgot to do something here should probably do something rather run command make fascinating we'll see how that goes hmm to be build more stuff so let's do a full build [Music] okay what happens if I wasn't make then look at that it actually starts running down there then we crash on is done but hey why did we crash oh I guess because that's normally what happens in terminal is that when the command that we run when that exits then we we don't want to keep going so we just exit the terminal um so who's doing that I guess somewhere in terminal which is we have an exit call who did this here it's G application oh we got it and lip quit okay gof on master PTY okay this is not exactly what I want to happen so let me turn this into a hook instead in the terminal legit so let's say on EOF or on command exit let's say if our command excellent we'll run it and we'll add a thing here and then in terminal we will use this terminal here right so on command exit you just do I can't even do it this way app quick okay so I think this should allow it to keep going and I guess in the case I mean we definitely care about this command exiting in packs to do as well but I'm just curious like so I guess a little laggy but it does seem to work oh and uh we got to react to this otherwise we'll just keep going mmm so what should we do here you know if I'm master pdy we fire the hook and I guess we can close the PTY after that it's no sense in keeping it open this is the oft anyway see parallel and MPT and Athiya is go back to minus one okay and Owen we should actually nuke the notifier at this point as well okay that's good you think that's good we could even do it this way [Music] okay building and it built so maybe we should actually print a little something here after the command finishes do we have some way of doing that and terminal digit I used to have something for that but I guess I've lost it it would be nice if this thing had a function that you could call it would just append as if it came from the terminal um I mean as if it came from the PTY and we'll just add something I didn't mean to do that though I can leave I mean it's not supposed to be there but I don't want to touch that line in this change also actually let me commit before I add too much stuff don't cuz that was just them on UF on command exit hook and PTY master stuff mm right and remaining changes were these things okay so we can pretending those along for now let's just commit this okay it's the witching location when seeing when guardians and you have you notice it gifts it's not yield exit client and decide or himself what to do okay now let's add something so that we can add text to the terminal like at the cursor basically so I think we'll call it out something like inject string and I'm just gonna make that pretend like there's text coming from the outside I wonder if terminal the VT terminal still has that functionality and Jack oh I did have inject stream just okay okay so it is used just you rarely see this that's barely used okay so we're gonna make that public and gonna be a string view because why not seems fine and then terminal which it will is just forward and terminal in jacket string the string okay then we can just use that when the command exits so here it will say that the con come in episode is Jack string but it's apparent I don't know how it should look like well maybe we could even do it to the color that we kind of cool fancy white I mean yellow sorry okay mm-hmm it would be good if we knew what the exit status of the command was actually it's kind of weird that we don't so what it's it's actually the PTY that you left it's not so much that command exited because the terminal legit itself doesn't have a concept of a command now that you think about it it just knows it just has a PTY so we know what the command was and actually we know what the pit of command was as well so we should probably stash that away so I'll say em and and let's do that okay what's certain here and we we don't have any running program or actually we can even say let's do a very gooey message box instead for now um a command is already running this is obviously not the final design of this and just I just want to have something show up if you try to run a command while one is already running okay so that was very very long we can probably do that a bit better like that's it right and and pid' when this exits though we should wait on it so it's entire sea is weighted and big status and no options shouldn't think we got any problems here but well insert in case we do it so that I can find it and and let's see what status actually we're gonna let's make a stringbuilder here this this gets a bit complicated because there are a few different ways that a command can exit right so we'll start by just saying builder and command should we have different colors also maybe we should it's getting complicated okay okay if [Music] what the hell is the name of its exit see if exited if stopped if signaled usually never wants to be cared about right well and then these are the exit code and signals respectively so [Music] this is why am I making this self complicated for myself I just do it this way instead command exited with God and then it won't say 'if or the code don't have to be fancy let's get rid of the string go there whatever builder I'll probably bring you back later run I want to do this nicely but let's just get to the point a different color and we'll put yet another color if it gets signal was it called term sig term stick so this will give us the signal but there's no way to get the signal name is it stare signal yeah yes their signal right okay maybe we should make the color here if the status is zero and we'll say the color is 32 otherwise it's 31 okay cuz I'm looking at like green for success and red for failure maybe kind of cool I'm forgetting one thing I have to actually clear the pit after I do this so I want to forget it and I think that's it Oh command is already running you say why do you believe that oh right it was backwards it's a bit annoying that the mouse lags from when I'm building it does feel very old-school okay so firing on commit exit hook and then what nothing happens I've been waiting for the pig so I think it seemed curious if we're even doing the white pig because it seems like something should have been printed whip-it returned 18 I mean I guess we could will return the pit yeah [Music] and then presumably we are trying to do one of these and then nothing happens why doesn't anything happen no okay it did happen we just didn't actually repaint after inject string which makes sense because we'll just make it update so normally or that was a cult inject string we want to trigger an update invalidate first how the heck cuz Terminal is trying to be very careful about repainting because it's very easy to the terminal emulator it's very easy to do and get this idea that you always have to redraw the whole terminal which is very inefficient and it makes it like completely sluggish to use the terminal so you always try to compute like a small area that changes so what we do in this terminal is we compute the individual lines the change like the rose and the terminal and then we only paint the lines that actually change between between updates instead of repainting the whole thing every time but in this case it seems like we're not invalidating line or maybe we are invalidating but not actually triggering a repaint so let's see how that it works in the terminal app terminal widget called on chart and for everything it gets and then it calls flush dirty lines so we need to actually do that and this is in the terminal widget so we could let's take the easy way out right now and just do this in inject string so after we inject the string will also say flush dirty lines because really the fact that we are painting whatever is in the terminal buffer that's just specific the tournament widget it's it's possible to to use BT terminal like it's just a generic sort of bt100 is terminal implementation and it's possible to use it without painting anything so the fact that we want to repaint after injecting something that's really specific to terminal widget which happens to be a painting user of BT terminal so I think it's fair to put the /q right okay so we are that's really cool and then I would want to run it as well right so my brain goes immediately to f5 or ctrl R for run and mmm I feel like ctrl R is maybe the most logical one because it's easier to me to finger on my keyword f5 I have to move my hand so I'm gonna go with ctrl R but it might turn out in the future that I want want to make it be f5 maybe I'm not sure but we'll go with control art to begin with let's commit what we have already those and um let's see let's do the terminal change first vt make check the string of the kid guy so clients can use this is it allows you to and arbitrary input that all right cursor position can you do it escape sequence just text whatever you like you can even do this cape surprises okay and then this adding the villain thingy and little bits just running make right now and I think we're good with that so let's commit this you know add a simple actually that snake so pressing ctrl e folks directory and very cool yeah I like it a lot okay so let's do run as well since that's what I said when I started my build and run so to facilitate this I'm going to tweak the wall project and add a run target because otherwise I would have to know what the name of the executable is and that gets a bit complicated so I don't want to think about that right now I'll just do this instead dot slash program yeah and in next video main will add any when shall we make run where is that thing it'll run okay it's pretty cool and let's see how this goes don't run oh look at that we run too fast we get this thing right yeah yeah that's okay and let's try to edit here are you build oh nothing to be done for all OH because I can't save I haven't implemented to say heave dammit alright alright let's commit this so hack studio ansible actually execute make in the project directory let's make a save thingy right click here so just make a really dumb save action in the app menu so I'm menu add action in common actions make say I don't have a save action okay oh let's steal one somewhere yeah we'll take this one because I'm this is the part I wanted to have an icon right okay and what are we gonna do when we save if G currently open file is empty well then whatever but if there is an open file say text editor right file G kindly open file it's just quick and dirty just so we can test it out okay so what's that not much okay fascinating okay wait save build why doesn't want to rebuild why doesn't wanna rebuild this is probably an issue of because main.cpp right may not always newer than main.cpp why is that so it's definitely writing something to disk well the timestamp doesn't change hmm well why does the timestamp change right bytes I know contacts change blah blah blah where the hell do we set them and time with files set end time is it probably oh maybe we never set the end time just because you write to a file mmm that's uh that's that's my bad let's go any file description and see when you write to something call it right and you want to go an inode file [Music] so let's see the rat is greater than or equal to 0 greater than 0 let's say if we wrote something set in time it's the current time dot TV sack this makes sense to me let's try it out so no let's build and then we actually write something in XXX save built the end and then it compiles again and as long as I don't change it it doesn't update then why why save build it builds again look at that okay well that's very awesome so let's commit that kernel change of date and time after a successful this was pretty silly updating location time files okay I guess this could technically fail well let's not worry about that failing right now cuz right bytes succeeded if M time fails I don't know I don't I don't know what are we gonna do right we'll just drop the end time update on the floor it doesn't seem like the end of the world and then right the quick and dirty save action packs to do a quick and dirty a simple same action I say move control s save stuff we open a spotter to okay so I think we're gonna stop here for today but let's take a look at our progress so we can now have a file open in this cool program what a cool hacks to do we can build it and we can't run it and these things are gonna need some cool icons but I'm not gonna do those right now but this is some pretty sweet progress I would say so if you made it this far then definitely thank you for hanging out and I hope you saw something interesting I saw that people were quite happy to see the start of the series um seems to be kind of you know hitting something with people making making them curious and that makes me happy because this is making me very curious to I'm happy to work on if you are interested in supporting my work then please do check me out on github sponsors or on patreon there are links in the description but obviously all of my content and all the code and everything is always going to be free so any kind of sponsorship or donations is strictly optional and I'm just happy that so many of you are interested in this stuff because it's so much fun to share it with you anyways thank you for hanging up and I'll see you next time bye
Info
Channel: Andreas Kling
Views: 3,642
Rating: undefined out of 5
Keywords: os hacking, os development, c++, c++ development, kernel development, operating system development, operating system programming, c++ programming, serenity os, serenity, serenity operating system, hobby os, hobby operating system, programming stream, os programming, c++ kernel, osdev, alternative operating systems, operating systems, ide, devtools, integrated development environment
Id: kUk9sxlaP-k
Channel Id: undefined
Length: 75min 16sec (4516 seconds)
Published: Wed Oct 23 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.