linux内核辅助工具

7 篇文章 1 订阅
4 篇文章 0 订阅

Linux多媒体
--------------
drivers\base
drivers\char
drivers\video
drivers\media
drivers\media\v4l2-core
drivers\media\platform

辅助工具-打印
-----------------
#define xe(fmt, ...) printk("\0013##############1.0 console start##############\n" fmt "###############1.0 console end###############\n", ##__VA_ARGS__)
#define xi(fmt, ...) printk("\0016##############1.0 console start##############\n" fmt "###############1.0 console end###############\n", ##__VA_ARGS__)

辅助工具-打印结构体
-----------------
来源:lib/vsprintf.c(vsnprintf:FORMAT_TYPE_PTR) -> lib/vsprintf.c(pointer:)
dev_info(&pdev->dev,"resource:%pR\n",pdev->resource);                          //打印设备资源信息.
print_hex_dump(KERN_ERR,"\t",0,16,1,pdev,sizeof(struct platform_device),true)  //smsc911x_drv_probe,十六进制打印pdev结构体信息.

int hex_dump_to_buffer_xe(const void *buf, size_t len, int rowsize, int groupsize,char *linebuf, size_t linebuflen, bool ascii)
{
    const u8 *ptr = buf;
    int ngroups;
    u8 ch;
    int j, lx = 0;
    int ascii_column;
    int ret;

    if (rowsize != 16 && rowsize != 32)
        rowsize = 16;

    if (len > rowsize)        /* limit to one line at a time */
        len = rowsize;
    if (!is_power_of_2(groupsize) || groupsize > 8)
        groupsize = 1;
    if ((len % groupsize) != 0)    /* no mixed size output */
        groupsize = 1;

    ngroups = len / groupsize;
    ascii_column = rowsize * 2 + rowsize / groupsize + 1;

    if (!linebuflen)
        goto overflow1;

    if (!len)
        goto nil;

    if (groupsize == 8) {
        const u64 *ptr8 = buf;

        for (j = 0; j < ngroups; j++) {
            ret = snprintf(linebuf + lx, linebuflen - lx,"%s%16.16llx", j ? " " : "",get_unaligned(ptr8 + j));
            if (ret >= linebuflen - lx)
                goto overflow1;
            lx += ret;
        }
    } else if (groupsize == 4) {
        const u32 *ptr4 = buf;

        for (j = 0; j < ngroups; j++) {
            ret = snprintf(linebuf + lx, linebuflen - lx,"%s%8.8x", j ? " " : "",get_unaligned(ptr4 + j));
            if (ret >= linebuflen - lx)
                goto overflow1;
            lx += ret;
        }
    } else if (groupsize == 2) {
        const u16 *ptr2 = buf;

        for (j = 0; j < ngroups; j++) {
            ret = snprintf(linebuf + lx, linebuflen - lx,"%s%4.4x", j ? " " : "",get_unaligned(ptr2 + j));
            if (ret >= linebuflen - lx)
                goto overflow1;
            lx += ret;
        }
    } else {
        for (j = 0; j < len; j++) {
            if (linebuflen < lx + 2)
                goto overflow2;
            ch = ptr[j];
            linebuf[lx++] = hex_asc_hi(ch);
            if (linebuflen < lx + 2)
                goto overflow2;
            linebuf[lx++] = hex_asc_lo(ch);
            if (linebuflen < lx + 2)
                goto overflow2;
            linebuf[lx++] = ' ';
        }
        if (j)
            lx--;
    }
    if (!ascii)
        goto nil;

    while (lx < ascii_column) {
        if (linebuflen < lx + 2)
            goto overflow2;
        linebuf[lx++] = ' ';
    }
    for (j = 0; j < len; j++) {
        if (linebuflen < lx + 2)
            goto overflow2;
        ch = ptr[j];
        linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
    }
nil:
    linebuf[lx] = '\0';
    return lx;
overflow2:
    linebuf[lx++] = '\0';
overflow1:
    return ascii ? ascii_column + len : (groupsize * 2 + 1) * ngroups - 1;
}

void hex_dump_xe(const char *level, const char *prefix_str, int prefix_type,int rowsize, int groupsize,const void *buf, size_t len, bool ascii)
{
    const u8 *ptr = buf;
    int i, linelen, remaining = len;
    unsigned char linebuf[32 * 3 + 2 + 32 + 1];

    if (rowsize != 16 && rowsize != 32)
        rowsize = 16;

    printk("\0013#############HEXDUMP START###############\n");
    for (i = 0; i < len; i += rowsize) 
    {
        linelen = min(remaining, rowsize);
        remaining -= rowsize;

        hex_dump_to_buffer_xe(ptr + i, linelen, rowsize, groupsize,linebuf, sizeof(linebuf), ascii);
        switch (prefix_type) 
        {
        case DUMP_PREFIX_ADDRESS:
            printk("%s%s%p: %s\n",level, prefix_str, ptr + i, linebuf);
            break;
        case DUMP_PREFIX_OFFSET:
            printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf);
            break;
        default:
            printk("%s%s%s\n", level, prefix_str, linebuf);
            break;
        }
    }
    printk("\0013##############HEXDUMP END################\n");
}

hex_dump_xe(KERN_ERR,"\t",0,16,1,pdev,sizeof(struct platform_device),true)  //smsc911x_drv_probe,十六进制打印pdev结构体信息.

控制台
-----------------
全局变量
exclusive_console
exclusive_console_stop_seq
console_seq
console_idx

console_init
 con_init
  
##############1.0 console start##############
###############1.0 console end###############


 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

胡致云

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值