linux kernel將關鍵資訊儲存到檔案做法 很好的調試方法,linuxkernel

來源:互聯網
上載者:User

linux kernel將關鍵資訊儲存到檔案做法 很好的調試方法,linuxkernel
linux kernel將關鍵資訊儲存到檔案做法      很好的調試方法

下面有2個樣本:
    1:儲存機器從開機到結束的VBATT;
    2:儲存uart接收到的資料到檔案;

意義不多說了。

以下是代碼:

#include <linux/fs.h>#include <asm/uaccess.h>#include <asm/unaligned.h>static  struct file *fp =NULL;int  write_to_file (char *buf, int size){     int ret = 0;     struct file *fp;     mm_segment_t old_fs;     loff_t pos = 0;     int nwrite = 0;     static int offset = 0;     static int first_flag=0;     /* change to KERNEL_DS address limit */     old_fs = get_fs();     set_fs(KERNEL_DS);     if( first_flag==0){     first_flag=1;     /* open file to write */     fp = filp_open("/data/at_log1", O_WRONLY|O_CREAT, 0640);     if (!fp) {         printk("%s: open file error\n", __FUNCTION__);         ret = -1;         goto exit;         }     }     pos=(unsigned long)offset;     /* Write buf to file */     nwrite=vfs_write(fp, buf, size, &pos);     offset +=nwrite;exit:     return ret;}int xxxx_exit(void){if (fp)          filp_close(fp, NULL);}


1:儲存VBATT與SOC:

static int adjust_soc(struct pm8921_bms_chip *chip, int soc,        int batt_temp, int chargecycles,        int rbatt, int fcc_uah, int uuc_uah, int cc_uah){    ------------   static char vbatt[100];    rc = pm8921_bms_get_simultaneous_battery_voltage_and_current(                            &ibat_ua,                            &vbat_uv);    if (rc < 0) {        pr_err("simultaneous vbat ibat failed err = %d\n", rc);        goto out;    }    chip->vbat_mv= vbat_uv/1000;    sprintf(vbatt,"%d        %d\n",the_chip->vbat_mv,calculated_soc);    write_to_file(vbatt,strlen(vbatt));    ----------}

2:將串口接收到的字元轉化為16進位儲存到檔案中:

static void msm_serial_hs_rx_tlet(unsigned long tlet_ptr){      ---------------    static char temp[1024];    rx_count = msm_hs_read(uport, UARTDM_RX_TOTAL_SNAP_ADDR);    /* order the read of rx.buffer */    rmb();    if (0 != (uport->read_status_mask & CREAD)) {        retval = tty_insert_flip_string(tty, msm_uport->rx.buffer,                        rx_count);        if (retval != rx_count) {            msm_uport->rx.buffer_pending |= CHARS_NORMAL |                retval << 5 | (rx_count - retval) << 16;        }        if(rx_count<=512){            //memcpy(temp,msm_uport->rx.buffer,rx_count);            for(i=0;i<rx_count;i++){            sprintf(temp+2*i,"%02x",msm_uport->rx.buffer[i]);            write_to_file(temp,strlen(temp));            }                        }          ----------------}




linux核心調試的主要方法

1。printk ,以及系統日誌。閱讀源碼,想象代碼啟動並執行情況,結合列印的資訊,推測問題所在。

2。核心調試器,例如 Kgdb 。

3。user mode linux 。

4。在虛擬機器上調試。例如 Bochs 。
參考資料:blog.csdn.net/...5.aspx
 
linux應用程式與核心的調試方法有什

裝個Insight,很簡單的



 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.