滚熊博客

滚熊博客

Thoughts, rants and discoveries on software development and related stuff.

How to look at the stack with gdb

·Linux

I was chatting with someone yesterday and they mentioned that they don’t really understand exactly how the stack works or how to look at it. So here’s a quick walkthrough of how you can use gdb to look at the stack of a C program. I think this would be similar for a Rust program, but I’m going to use C because I find it a little simpler for a toy example and also you can do Terrible Things in C more easily. our test program Here’s a simple C program that declares a few variables and reads two strings from standard input. One of the strings is on the heap, and one is on the stack. #include <stdio.h> #include <stdlib.h> int main() { char stack_string[10] = "stack"; int x = 10; char *heap_string; heap_string = malloc(50); printf("Enter a string for the stack: "); gets(stack_string); printf("Enter a string for the heap: "); gets(heap_string); printf("Stack string is: %s\n", stack_string); printf("Heap string is: %s\n", heap_string); printf("x is: %d\n", x); } This program uses the extremely unsafe function gets which you should never use, but that’s on purpose – we learn more when things go wrong. step 0: compile the program. We can compile it with gcc -g -O0 test.

Read More →
#gdb#stack

Building cgit on macOS

·Linux

Checkout and init the submodule. git clone git://git.zx2c4.com/cgit cd cgit git submodule init git submodule update Install gettext through brew. brew install gettext Then create a cgit.conf file and set complier/linker flags to use the gettext library installed before. CFLAGS = -g -O2 -Wall -I/usr/local/opt/gettext/include LDFLAGS = -L/usr/local/opt/gettext/lib Finish up with a simple make command. make

Read More →
#cgit#macos

Vim Cheat Sheet

·Linux

A Great Vim Cheat Sheet Essentials Cursor movement (Normal/Visual Mode) h j k l - Arrow keys w / b - Next/previous word W / B - Next/previous word (space seperated) e / ge - Next/previous end of word 0 / $ - Start/End of line ^ - First non-blank character of line (same as 0w) Editing text i / a - Start insert mode at/after cursor I / A - Start insert mode at the beginning/end of the line o / O - Add blank line below/above current line Esc or Ctrl+[ - Exit insert mode d - Delete dd - Delete line c - Delete, then start insert mode cc - Delete line, then start insert mode Operators Operators also work in Visual Mode d - Deletes from the cursor to the movement location c - Deletes from the cursor to the movement location, then starts insert mode y - Copy from the cursor to the movement location > - Indent one level < - Unindent one level You can also combine operators with motions. Ex: d$ deletes from the cursor to the end of the line. Marking text (visual mode) v - Start visual mode V - Start linewise visual mode Ctrl+v - Start visual block mode Esc or Ctrl+[ - Exit visual mode Clipboard yy - Yank (copy) a line p - Paste after cursor P - Paste before cursor dd - Delete (cut) a line x - Delete (cut) current character X - Delete (cut) previous character d / c - By default, these copy the deleted text Exiting :w - Write (save) the file, but don’t quit :wq - Write (save) and quit :q - Quit (fails if anything has changed) :q!

Read More →
#vim

去掉doc88,360doc,csdn和sfgg的登陆后复制限制

·Linux

各大站都搞这个登陆复制,真的恶心, 尤其是csdn,各种和谐, 虽然有命令,但是每次敲都贼麻烦, 来个油猴脚本吧~~ /* eslint-disable no-undef */ /* eslint-disable no-eval */ // ==UserScript== // @name 去掉doc88,360doc,csdn和segmentfault的登陆后复制限制 // @author ALEX.XU // @version 1.0.0 // @match *://*/* // @require https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.min.js // @run-at document-start // @grant unsafeWindow // ==/UserScript== (function() { 'use strict'; $(function(){ if (/www.doc88.com/.test(location.href) || /www.360doc.com/.test(location.href)){ function oncopy() { return true; } setInterval(function(){ try{ unsafeWindow.logined = 1 unsafeWindow.u_v = 1 document.body.oncopy = oncopy //360doc }catch(e){ console.log(e)} }, 1000) }else if(/blog.csdn.net/.test(location.host)){ console.log(mdcp, hljs); if (typeof(mdcp)!="undefined" && 'copyCode' in mdcp){ // $("code").attr("onclick","mdcp.copyCode(event)") // 直接来个狠的 document.body.contentEditable = true; }else if (typeof(hljs)!="undefined" && 'copyCode' in hljs){ $("*").one("mousemove", function(){ $(".hljs-button").attr("onclick","hljs.copyCode(event)") }) } } else if(/segmentfault.com/.test(location.host)){ $("<div></div>").attr("id","SFUserId").appendTo("body") } }) }())

Read More →
#csdn

win10 笔记本 同时接入无线(外网)和有线(内网)

·Linux

连接内网和无线网络 内网和外网都不要禁止,win10系统,以管理员身份运行CMD,在CMD中输入route print IPv4 路由表 上面一行是外网,下面一行是内网。 内网的跃点数高,要手动修改外网的跃点数,打开无线网(外网)IP4属性框中的高级,接口跃点数设置为1。 进入cmd通过route命令来重新设置网络 执行:route delete 0.0.0.0 (删除对所有ip的默认路由设置) 执行:route add 0.0.0.0 mask 0.0.0.0 192.168.0.1(将所有ip路

Read More →
#linux#windows

网络字体包压缩优化方案

·Linux

本文将介绍如何缩小网络字体包大小及优化其加载过程。 优化思路 将字体包转换为 woff2 格式。它具有更小的体积,对现代浏览器非常友好,且无需再 gzip 压缩。 使字体包中仅保留英文、数字、常用字符和常用汉字。 使用非堵塞方式加载字体包。 QA 1、TTF 如何转换为 WOFF2? 使用fonttools转换格式。它是一个依赖于 python 的工具。(若转换时候报错,需要根据提示安装对应依赖的库。) (1)安装: pip install fonttools (2)转换例子: pyftsubset example.ttf --layout-features="" --unicodes=U+0020-007E,U+4E00-9FA5 --flavor=woff2 --output-file=example.woff2 注意

Read More →
#字体包#压缩优化方案

[solved]modprobe: ERROR: ../libkmod/libkmod-module.c:832 kmod_module_insert_module() could not find module by name='off'

·Linux

exute sudo modprobe nvidia error: modprobe: ERROR: ../libkmod/libkmod-module.c:832 kmod_module_insert_module() could not find module by name=‘off’ 02615-oak8kunndy9.png Nvidia对他们的安装做了一些改动。 现在,Nvidia库位于/usr/lib/x86_-linux-gnu中 blacklist-nvidia.conf文件位于/lib/modprobe.d/中 在blacklist-nvidia.conf中,仍然存在未经注释的 alias nvidia off。 注释掉 alias nvidia off 后,如图所示: $ cat /lib/modprobe.d/blacklist-nvidia.conf# Do not modify# This file was generated by nvidia-primeblacklist nvidiablacklist nvidia-drmblacklist nvidia-modeset#alias nvidia offalias nvidia-drm off 参考链接 : https://forums.linuxmint.com/viewtopic.php?t=274958 https://github.com/Bumblebee-Project/Bumblebee/issues/951

Read More →
#nvidia#modprobe

gitExtension 合并与衍合

·Linux

注意到:以下的操作主要是用gitExtension来操作的。 gitExtension配置教程:http://www.cnblogs.com/sorex/archive/2011/08/10/2132359.html 内容提要: Q1、git如何让develop分支合并到master Q2、git如何让develop分支衍合到master Q3、git如何搭建server。 关于Q1: step0:将devel

Read More →
#windows#gitExtension