• 生成asm-offset


    因为不善于在Makefile中调用shell的相关工具,所以关于asm-offsets.h中的产生的16进制数并不知如何做到。

    因此自己写了个脚本,可以生成同样的文件(再次造了轮子)。

    参考:https://lkml.org/lkml/2001/10/6/3

    #脚本offset.awk
    1
    /^->$/{printf(" ");next} 2 /^->.*/{sym = $1; val = $2; $1 = ""; $2 = ""; sub(/^->/,"",sym);sub(/^$/,"", val);printf("#define %-15s %3d /* 0x%x %s */ ", sym, val, val, $0)}
    //测试文件asm-offset.c
    #include <stddef.h>
    
    #ifndef offsetof                                                                                                   
    #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
    #endif
    
    #define DEFINE(sym, val) 
        asm volatile("
    ->" #sym " %0 " #val : : "i" (val))
    
    #define BLANK() asm volatile("
    ->" : : )
    
    struct university
    {
        int soochow;
        int seu;
        int tsing;
        int peking; 
        int nju;
        int sjtu;
    };
    
    int main(void)
    {
        BLANK();
        DEFINE(SOOCHOW, offsetof(struct university, soochow));
        BLANK();
        DEFINE(SEU,     offsetof(struct university, seu));
        BLANK();
        DEFINE(TSING,   offsetof(struct university, tsing));
        BLANK();
        DEFINE(PEKING,  offsetof(struct university, peking));
        BLANK();
        DEFINE(NJU,     offsetof(struct university, nju));
        BLANK();
        DEFINE(SJTU,    offsetof(struct university, sjtu)); 
        BLANK();
    }

    使用:

    1 gcc -S asm-offset.c; awk -f offset.awk asm-offset.s > asm-offset.h; rm asm-offset.s

    输出:

    //asm-offset.h                                                                                                                   
    
    #define SOOCHOW            0    /* 0x0    offsetof(struct university, soochow) */
    
    #define SEU                4    /* 0x4    offsetof(struct university, seu) */
    
    #define TSING              8    /* 0x8    offsetof(struct university, tsing) */
    
    #define PEKING            12    /* 0xc    offsetof(struct university, peking) */
    
    #define NJU               16    /* 0x10   offsetof(struct university, nju) */
    
    #define SJTU              20    /* 0x14   offsetof(struct university, sjtu) */
  • 相关阅读:
    Android开发总结
    Java开发中的23种设计模式详解(转)
    Linux下Tomcat的安装配置
    Linux下Tomcat的启动、关闭、杀死进程
    在陌生Linux环境查看Tomcat服务的方法
    JAVA用freemarker生成复杂Excel。(freemarker)
    JAVA生成Word文档(经过测试)
    jvm 内存溢出 在myeclipse中加大tomcat的jvm内存 java.lang.OutOfMemoryError: PermGen space
    TabHost
    ProgressBar
  • 原文地址:https://www.cnblogs.com/openix/p/3335076.html
Copyright © 2020-2023  润新知