Skip to content

Instantly share code, notes, and snippets.

@godmachine81
Created February 27, 2012 07:21
Show Gist options
  • Save godmachine81/1922195 to your computer and use it in GitHub Desktop.
Save godmachine81/1922195 to your computer and use it in GitHub Desktop.
<god-zotac> not sure about that, i haven't ever done exactly what you are doing
<god-zotac> is this for a school project or something?
<motherbrain> I am just worried that the kprint message would scroll by to fast for me to see...
<god-zotac> you can enable kernel message printing to file
<motherbrain> your saying print it to a log file.... we how would you do that
<god-zotac> if you have kernel debugging enabled, there is a cmdline boot option that will let messages be appended to a defined file
<god-zotac> i'm not sure what the cmd line is to log kernel debugging though ill have to google that for ya
<god-zotac> http://elinux.org/Kernel_Debugging_Tips
<god-zotac> that page seems to be pretty helpful for everything you have asked about :)
<motherbrain> thanks but I have a more fundemental problem how do you enable kernel debugging . Is that just an option in a grub file... Basically I need some step by step of how you enable it in linux
<god-zotac> no you have to do it at kernel configuration
<god-zotac> in the kernel config
<god-zotac> and then compile it with those options enabled
<god-zotac> then you'll need to follow the guide on that page i linked
<motherbrain> so are you saying when I do ./configure their is some option I have to turn on. Is that how you do it?
<god-zotac> you don't do ./configure on the kernel
<god-zotac> you do make oldconfig and/or make menuconfig (make xconfig = GUI configuration)
<motherbrain> I do ./configure, make , make all when building what do you mean
<god-zotac> not on the kernel you don't
<god-zotac> ./configure just generates Makefiles for most source packages
<god-zotac> the kernel requires more than that
<motherbrain> O, sorry ya your right is it in the configurations of make menuconfig that I set this
<motherbrain> kernel debugging stuff
<god-zotac> you wouldn't want to do a ./configure THIS_OPTION=N CONFIG_THAT=Y (for all 2000 + options for kernel)
<motherbrain> so is it when I do ./configure or when I do make menuconfig that I set the kernel debugging stuff
<god-zotac> once again.. you don't do ./configure on the kernel
<god-zotac> make menuconfig will save a .config for your kernel
<god-zotac> when you run 'make' it will build based on the .config
<god-zotac> to answer your question about the kernel debugging options, it would be in make menuconfig that you will set it.. it will be much easier to install the qt development libraries and use xconfig instead of menuconfig
<motherbrain> ok then all it is is some setting in the .config file I have to modify before I issue make then make install
<god-zotac> the layout of menuconfig is limiting when setting things that you don't exactly know where they are
<god-zotac> and searching for things with xconfig is much more convienient
<god-zotac> i've built a lot of kernels
<god-zotac> don't think that just because xconfig has a GUI that it is aimed more at n00bs, thats not the case
<god-zotac> i don't think you would really want to just do make install
<god-zotac> building a kernel is much different than compiling other source code in the terms of how you do it
<god-zotac> typically for programs you do ./configure ; make; make install
<motherbrain> then why should I use xconfig over just .config
<god-zotac> for kernel you normally would do: zcat /proc/config.gz > /usr/src/linux/.config ; make oldconfig ; make xconfig; make modules_install; cp arch/x86/boot/bzImage /boot/linux-#.#.#-custom-#.img
<god-zotac> .config is a file not an option
<god-zotac> oops i left out the actual make in that line i gave you
<motherbrain> And must I have to rebuild the kernel to enable kernel debugging is their no other way other then 1) .config file or 2) xconfig .... no patches or anything
<god-zotac> for kernel you normally would do: zcat /proc/config.gz > /usr/src/linux/.config ; make oldconfig ; make xconfig; make; make modules_install; cp arch/x86/boot/bzImage /boot/linux-#.#.#-custom-#.img
<god-zotac> unfortuantely no.. you have to build it into the kernel
<god-zotac> unless you could build it as a module
<god-zotac> but in that case debugging would not begin until the module was loaded
<motherbrain> well I was looking thru this http://www.ibm.com/developerworks/linux/library/l-kdbug/ and it seems that their is a different way correct me if I am wrong
<motherbrain> " unless you could build it as a module
<motherbrain> but in that case debugging would not begin until the module was loaded" Ya you could do that with like insmod but that is not what I would be looking for since like you said it would miss alot of things
<god-zotac> i looked at your link
<god-zotac> it leaves out the parts about configuring
<god-zotac> its just telling you how to patch it, and what to enable in the config
<god-zotac> first thing you want to do is get the exact same kernel that you have working
<god-zotac> the source for it i mean
<god-zotac> then you want to use the same configuration that you have now
<god-zotac> so thats what zcat /proc/config.gz > /usr/src/linux/.config does
<god-zotac> it reads your current kernels config and outputs it to a file
<god-zotac> that way you don't have to reconfigure every single piece by hand
<motherbrain> yes but what is this patch they are talking about what does that suppose to do.
<god-zotac> the patch is for the kdb options in the configuration to show up and allow you to say Y or N to them
<motherbrain> well wouldn't I want that
<god-zotac> yes
<god-zotac> you want that
<motherbrain> so I have to do the patch?
<god-zotac> so after you get your .config in tact you'd patch
<god-zotac> then run make oldconfig
<god-zotac> then run make menuconfig or make xconfig
<motherbrain> curious why make oldconfig over menuconfig
<god-zotac> oldconfig takes your old configuration and rewrites it with the newer options
<god-zotac> the ones the patch gives
<motherbrain> I am just curious what the difference and why you would use one over the other old , menu ,..etc config
<god-zotac> oldconfig means you already have a .config you want to use
<god-zotac> i didn't say to use oldconfig over anything
<god-zotac> i said to use it first
<god-zotac> and then use either menuconfig or xconfig
<god-zotac> xconfig is a QT GUI
<god-zotac> it has a left side tree of each category in the kernel
<god-zotac> and a right side split view
<god-zotac> the top being the options in the subcategories
<god-zotac> the bottom being the option information
<god-zotac> menuconfig is just a ncurses frontend for command line
<god-zotac> do you want me to make a screenshot of xconfig and then one of menuconfig
<god-zotac> and let you see the differences?
<motherbrain> ya, please if you don't mind
<motherbrain> so is this all I will have in theory ""for kernel you normally would do: zcat /proc/config.gz > /usr/src/linux/.config ; make oldconfig ; make xconfig; make; make modules_install; cp arch/x86/boot/bzImage /boot/linux-#.#.#-custom-#.img " What is the difference in oldconfig and menuconfig why not make menuconfig"
<god-zotac> http://upload.wikimedia.org/wikipedia/en/0/02/Linux-kernel-menuconfig.png == menuconfig interface
<god-zotac> http://syrlug.org/images/screens/xconfig.png == xconfig interface
<god-zotac> What is the difference in oldconfig and menuconfig why not make menuconfig" thought i explained what oldconfig done..
<god-zotac> it isn't an option of choosing between oldconfig and menuconfig
<god-zotac> oldconfig means you already have .config present in the directory and you are going to be building based on that
<god-zotac> and any patches or changes to be applied to that .config
<god-zotac> menuconfig is the interface you choose to use for configuring.. i said you had the option of menuconfig or xconfig
<god-zotac> not an option of oldconfig or menuconfig
<motherbrain> ok but if I have a .config file already I would use oldconfig and not menuconfig correct. Because if I used menuconfig would it replace my .config setting / erase them
<god-zotac> no it wont do that
<god-zotac> oldconfig will just prompt you for the changes that aren't in your config
<god-zotac> menuconfig will show all the options and let you verify that they are all enabled that you need
<motherbrain> yes but doesn't menuconfig write out your .config file if one doesn't exist just worried I don't want anything to lose my current settings
<god-zotac> you won't lose nothing
<god-zotac> your kernel config will stay the same and still be gzipped at /proc/config.gz
<god-zotac> menuconfig will read from the .config you have in the kernel source directory it won't over write it with an empty one
<god-zotac> the only thing that will do that is make mrproper
<motherbrain> ls /proc | grep config shows me nothing I DON"T HAVE config.gz ???
<motherbrain> in proc folder
<god-zotac> hrm
<god-zotac> why would you not just ls /proc/config.gz instead of ls /proc|grep config ?
<motherbrain> either way no such file
<god-zotac> try ls /boot/$(uname -r)
<motherbrain> ya I could do it your way to
<god-zotac> sorry
<motherbrain> O your looking for my version
<god-zotac> try ls /boot/config-$(uname -r)
<motherbrain> /boot/config-2.6.38-10-generic
<god-zotac> ok then copy that file to your kernel source directory as .config
<god-zotac> i.e. if your kernel source is in /usr/src/linux then do:: cp /boot/config-2.6.38-10-generic /usr/src/linux/.config
<motherbrain> are you saying config-2.6.38-10-generic unzipped file is the equivalent to config.gz
<god-zotac> yes
<god-zotac> your current kernel doesn't have config_ikconfig=y or config_ikconfig_proc=y
<god-zotac> you might want to enable that also in your new kernel
<motherbrain> ok curious I see their is Kconfig what are those and are they different then .config
<god-zotac> Kconfig is what menuconfig/xconfig references for options, information, etc
<motherbrain> I see
<god-zotac> the Makefile in each directory will check whether your .config has options set to Y or M or not set at all
<god-zotac> and build them accordingly
<motherbrain> if I don't have a .config file do I just create one before copying /boot/config-2.6.38-10-generic to it
<god-zotac> no
<god-zotac> when you copy it it will be there if it doesn't exist
<god-zotac> if one does exist it will just overwrite the one that is already there (which there shouldn't be one there)
<motherbrain> O, I see ya cp command does that
<god-zotac> did you ever answer me about why you are doing all this?
<god-zotac> is it for a school project or what?
<motherbrain> it is more of a school research project into OS stuff
<god-zotac> ok whats the exact assignment?
<god-zotac> for generalized OS stuff i wouldn't think it would require you build a custom kernel
<god-zotac> any teacher that has ever built a kernel themselves wouldn't expect a student to just dive into that as a project
<god-zotac> and expect to be able to provide specific debugging information on it
<god-zotac> getting a kernel compiled and booting properly is a task alone
<god-zotac> requiring a student have a Linux OS and a boot loader installed is a bit far fetched
<god-zotac> unless they are furnishing the equipment
<motherbrain> being able to understand how the linux kernel starts up , how to compile / build your own custom linux kernel or add on to linux kernel via modules or hardcoding it into the kernel. I have already done modules so I am pretty good at that, have successful built a kernel and got the vmlinuz ,..etc files. Now I am trying to figure out how to get debugging enable to get a better look at how to add my h
<motherbrain> ard coded functions and where flow of linux kernel goes thru debugging.
<god-zotac> don't seem like thats what they are looking for
<motherbrain> we I also am very curious of things so I just really want to understand a few extra things in the process
<god-zotac> they are basically wanting to know that the kernel is loaded from your bootloader, the kernel loads based on how it was configured, mounts the OS partition, runs init, which will run a script to load the modules via insmod or modprobe, and then other init.d / rc.d services depending on distribution
<god-zotac> the kernel is nothing more than a binary compiled to compatible to your machines CPU
<motherbrain> I know this but I am curious to get a little more indepth by setting up KDB
<god-zotac> im just saying that if you don't understand the kernel configs and kconfig things fully, then how are you going to understand any output of the debug logs?
<motherbrain> and now that we where on the KDB subject I was just wondering about the Kconfig files so that is why I asked
<god-zotac> maybe dmesg >/tmp/kernelmessages may help you more than kdb
<god-zotac> try dmesg|less first
<motherbrain> yes I have used dmesg in the past but I don't know how precise this is to KDB. What is the difference ?
<god-zotac> see if it provides any info you are seeking
<god-zotac> i've never used kdb, but i assume it will give memory addresses and I/O info
<god-zotac> usually you'd want to use debugging utilities for finding a bug.. not just for observing the chain reaction of how things work ;)
<motherbrain> well, what I really wanted to do is beable to kprint line by line or use kdb to step thru line by line of the loading process. cann't really do that with dmesg
<god-zotac> why can't you?
<god-zotac> dmesg gives you exact times that things were loaded and are in chronological order of the boot process
<god-zotac> dmesg gives me 1316 lines of information, thats pretty precise if you ask me
<motherbrain> with dmesg I can only use at command line and it is just displaying what is in the /var/log file
<motherbrain> I want to beable to step thur the kernel more precisely line by line , trace the function stack , registers values ,...etc cann't do that with dmesg
<god-zotac> what does kdb do other than give you more detailed information that dmesg outputs?
<god-zotac> does kdb let you do steps?
<motherbrain> I would think it would be like gdb but for the loading and kernel. how can you get this much control with only dmesg ?
<god-zotac> dmesg is for information
<god-zotac> which would be what you need for a project
<god-zotac> kdb would be for viewing actual pieces of code in a certain memory register
<god-zotac> or setting break points at certain functions
<motherbrain> Ya , understand and I am really finished with this project I just want to know more
<god-zotac> also will cause a kernel panic if you don't do it right
<god-zotac> and if you are trying to do it at boot time then how are you going to issue the commands for the break points / registers if your init process hasn't activated or completed?
<motherbrain> then what is kdb used for?
<god-zotac> i don't think kdb is intended for debugging the boot process
<god-zotac> but instead for debugging kernel calls after the system is already up
<god-zotac> dmesg doesn't let you set break points or nothing, but i don't see why you'd need them just for observing the process of things
<god-zotac> i understand you are wanting a more indepth look at the kernel and how it works
<god-zotac> but there is no better place to look than the actual source code for that
<motherbrain> ok say I want to step thru the kernel line by line printing out something. Is the only way to use a kprint statement after each line/between each line and then recompile would that be the way?
<motherbrain> is their any kernel function that would allow me to pause at a certain point in the load until I hit a button is their like a kpause function or some kernel function that waits until something is pressed to continue executing?
<god-zotac> yes i think there is
<motherbrain> what
<god-zotac> look in the kernel hacking section of the configuration
<god-zotac> CONFIG_FUNCTION_TRACER:
<god-zotac> Enable the kernel to trace every kernel function. This is done
<god-zotac> by using a compiler feature to insert a small, 5-byte No-Operation
<god-zotac> instruction at the beginning of every kernel function, which NOP
<god-zotac> sequence is then dynamically patched into a tracer call when
<god-zotac> tracing is enabled by the administrator. If it's runtime disabled
<god-zotac> (the bootup default), then the overhead of the instructions is very
<god-zotac> small and not measurable even in micro-benchmarks.
<god-zotac> CONFIG_KGDB:
<god-zotac> If you say Y here, it will be possible to remotely debug the
<god-zotac> kernel using gdb. It is recommended but not required, that
<god-zotac> you also turn on the kernel config option
<god-zotac> CONFIG_FRAME_POINTER to aid in producing more reliable stack
<god-zotac> backtraces in the external debugger. Documentation of
<god-zotac> kernel debugger is available at http://kgdb.sourceforge.net
<god-zotac> as well as in DocBook form in Documentation/DocBook/. If
<god-zotac> unsure, say N.
<god-zotac> CONFIG_MAGIC_SYSRQ:
<god-zotac> If you say Y here, you will have some control over the system even
<god-zotac> if the system crashes for example during kernel debugging (e.g., you
<god-zotac> will be able to flush the buffer cache to disk, reboot the system
<god-zotac> immediately or dump some status information). This is accomplished
<god-zotac> by pressing various keys while holding SysRq (Alt+PrintScreen). It
<god-zotac> also works on a serial console (on PC hardware at least), if you
<god-zotac> send a BREAK and then within 5 seconds a command keypress. The
<god-zotac> keys are documented in <file:Documentation/sysrq.txt>. Don't say Y
<god-zotac> unless you really know what this hack does.
<god-zotac> CONFIG_DEBUG_KOBJECT:
<god-zotac> If you say Y here, some extra kobject debugging messages will be sent
<god-zotac> to the syslog.
<god-zotac> CONFIG_DEBUG_INFO:
<god-zotac> If you say Y here the resulting kernel image will include
<god-zotac> debugging info resulting in a larger kernel image.
<god-zotac> This adds debug symbols to the kernel and modules (gcc -g), and
<god-zotac> is needed if you intend to use kernel crashdump or binary object
<god-zotac> tools like crash, kgdb, LKCD, gdb, etc on the kernel.
<god-zotac> Say Y here only if you plan to debug the kernel.
<god-zotac> CONFIG_BOOT_PRINTK_DELAY:
<god-zotac> This build option allows you to read kernel boot messages
<god-zotac> by inserting a short delay after each one. The delay is
<god-zotac> specified in milliseconds on the kernel command line,
<god-zotac> using "boot_delay=N".
<god-zotac> It is likely that you would also need to use "lpj=M" to preset
<god-zotac> the "loops per jiffie" value.
<god-zotac> See a previous boot log for the "lpj" value to use for your
<god-zotac> system, and then set "lpj=M" before setting "boot_delay=N".
<god-zotac> NOTE: Using this option may adversely affect SMP systems.
<god-zotac> I.e., processors other than the first one may not boot up.
<god-zotac> BOOT_PRINTK_DELAY also may cause DETECT_SOFTLOCKUP to detect
<god-zotac> what it believes to be lockup conditions.
<motherbrain> well thanks for all and when I have more time i will try it out. But right now I am just curious of a function I could use to pause at a point in the kernel and display somethings. I know kprint would print for me but I don't know if their is any pause which I can use with a touch of the keys since interrupts are probably disabled or not setup at some points
<god-zotac> did you see the MAGIC_SYSRQ configuration option?
<god-zotac> and read the Documentation/sysrq.txt
<god-zotac> https://gist.github.com/1922103
<motherbrain> ya, i see it in the documentation folder of linux source in sysrg.txt and on your link as well. I think I am all set. Just one last thing when would somebody need to use a kernel debugger couldn't they always use kprint and a few homemade functions to dump whats in memory /registeries whenever they wanted
<god-zotac> why would you want to modify all source code by hand in the kernel to do that when you can simply enable a function that is already designed to do it?
<motherbrain> well if you are not using KDB then how would you dump memory or registers/variables print calling stack ,...etc with out your own function and kprint. And you make it sound like you are cluttering up the source all you would have to do is create one extra file for your stuff and add it to the kernel
<motherbrain> then just call your stuff whenever you need in the source and recompile
<god-zotac> but what i am saying is there is already an option in the kernel configuration to do just that
<motherbrain> plus if you screwed something up you always can get another copy :)
<god-zotac> why reinvent the wheel?
<motherbrain> or you saying apart from the KDB I may not have caught all of what you where saying you sent me a bunch at a time
<god-zotac> what i am saying is, forget kdb
<god-zotac> there is everything you need for the things you are wanting in the kernel sources mainline
<motherbrain> true you shouldn't reinvent the wheel unless your learning
<god-zotac> no need for kdb and patches
<motherbrain> ok then can you take me thru the process of enabling this with out kdb and patches
<motherbrain> one more time
<god-zotac> i just gave you the configs and t he info pertaining to them
<god-zotac> once you get to menuconfig or xconfig just find those options in the kernel hacking section and say Y to them
<god-zotac> save the config
<god-zotac> then compile the kernel
<god-zotac> then edit your boot loader config to boot the new kernel
<god-zotac> as far as a step by step process of doing it all, no im sorry, i don't have the time to do all that.. it is well documented online and in the kernel source's documentation though
<motherbrain> ok sorry for my stupidity but I am using xchat and I am trying to say all are conversation but when i go to save transcript it doesn't save everything I lost a bunch in some way
<god-zotac> just select all the text and pastebin it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment